A Comprehensive List of Python in Excel Resources

Andrew Huang
Team Anaconda
The 2024 U.S. presidential election offers a rich dataset for data scientists to explore. Using the open-source Python libraries Panel, hvPlot, and HoloViews we created visualizations like Sankey diagrams, heatmaps, and box charts to illustrate key political dynamics, including voter turnout, partisan divisions, and swing state competitiveness. Explore the code used to build these visualizations in Anaconda Notebooks.
These visualizations reveal patterns such as regional disparities in turnout and shifts in issue-based support, offering valuable insights into U.S. politics. Beyond elections, this project demonstrates how combining datasets and advanced visualization tools can simplify complex data, uncover actionable trends, and deliver impactful narratives for businesses and organizations.
We sourced data for this project from the following:
Using data from AP VoteCast, we built a custom Sankey diagram app with HoloViews. Explore our dynamic Sankey app here and create your own analysis.
Sankey diagrams are excellent tools for visualizing the relationships between two or more categories, making it easier to understand proportions, patterns, and the movement of values within a system. The app visualizes the responses to two questions:
On the question of whether Trump can win the general election, Republicans overwhelmingly exude confidence, with the majority believing he can succeed. Democrats, on the other hand, are largely skeptical, leaning heavily toward “No.” Independents, unsurprisingly, are split, mirroring their position as political wild cards.
The left side of the diagram represents respondents’ political leanings, grouped into “Republican/Lean Rep,” “Independent,” and “Democrat/Lean Dem.” The right side indicates their responses to whether Trump can win, categorized as “Yes” or “No.”
One interesting post-election data point that’s been widely discussed is the relationship between education and support for the Make America Great Again (MAGA) movement.
The education Sankey diagram confirms this trend: support for the MAGA movement varies across educational attainment levels. Those with a high school education or less are more likely to support MAGA, while postgraduates tend to oppose it. College graduates, notably, show a near-even split between “Yes” and “No,” highlighting diverse perspectives within this group.
One surprising detail is the presence of postgraduates who support MAGA—a smaller segment, but one that challenges assumptions about the movement’s alignment with education levels. This could suggest a more ideologically diverse base within the MAGA movement than commonly perceived.
This Sankey diagram visualizes responses to two questions:
The left side of the diagram represents respondents’ education levels, grouped into “High school or less,” “Some college/assoc. degree,” “College graduate,” and “Postgraduate study.” The right side indicates their response to MAGA, categorized as “Yes” or “No.”
When gender enters the equation, a clear divide emerges. Men are more likely to have a more favorable view towards Trump than women are. However, what’s surprising is that while a higher proportion of men have a favorable view of Trump, more than half of women hold a favorable view of him, too—despite being critiqued for his polarizing rhetoric around gender and women’s issues.
Even more surprising is the response from nonbinary and other genders. While this is a small group, their opinions seem evenly spread, showing no overwhelming consensus on Trump’s favorability based on gender.
This Sankey diagram visualizes responses to two questions:
The left side of the diagram represents respondents’ gender, grouped into “Men,” “Women,” and “Nonbinary/Other.” The right side indicates their response to MAGA, categorized as “Yes” or “No.”
The 2024 election saw the question of foreign aid shape the political discourse in the nation, namely military and financial support—or lack thereof—for both Ukraine and Israel.
This diagram paints a vivid picture of how political affiliation shapes views on foreign aid. Democrats strongly favor aid to both Ukraine and Israel, showing a consistent stance. Republicans, meanwhile, oppose aid to Ukraine while strongly favoring aid to Israel—a divide that reflects the geopolitical narratives emphasized in conservative politics.
What’s particularly interesting is the flow between the Ukraine and Israel categories. Some respondents who “Strongly oppose” aid to Ukraine still favor aid to Israel, reflecting differing perceptions of the two conflicts and their importance to U.S. interests.
This Sankey diagram visualizes responses to three questions:
The diagram is divided into three sections. The left side shows respondents’ stance on Ukraine aid, categorized as “Strongly oppose,” “Somewhat oppose,” “Somewhat favor,” or “Strongly favor.” The center represents political affiliations: “Republican/Lean Rep,” “Democrat/Lean Dem,” and “Independent.” The right side indicates respondents’ stance on Israel aid, categorized as “Strongly oppose,” “Somewhat oppose,” “Somewhat favor,” or “Strongly favor.”
Using data from the University of Florida’s Election Lab, this plot tells a story of how voter turnout in the United States has evolved over more than two centuries, highlighting distinct differences between presidential and midterm elections. It offers a lens into the dynamics of civic engagement and how historical, social, and political contexts shaped voter participation.
Presidential elections (blue line) consistently see higher turnout rates compared to midterm elections (red line). This trend underscores the heightened public interest and stakes typically associated with electing a president versus congressional contests. However, the plot also reveals several fascinating shifts based on the history of the United States:
What’s most interesting about this graph is that it shows how we’re approaching an all-time high of voter participation. In fact, data from the National Association of Counties found that the 2024 cycle had the second highest voter turnout (63.3 percent) since 1960, only topped by the 2020 election (66.7 percent).
While modern voter turnout is higher than ever, regionally it’s a different story.
This map visualizes the turnout rates for the voting eligible population (VEP) in the 2024 general election across the United States. Each state is color-coded based on its turnout rate, ranging from purple (low turnout) to yellow (high turnout).
The most surprising aspect of this trend is how the number of swing states has plummeted in recent decades, despite the perception of close national elections. This reflects how deeply entrenched partisan loyalties have become, with fewer states flipping between parties, even as the overall national margin remains competitive. It also underscores the growing importance of a small number of battleground states in determining the outcome of presidential elections.
This line chart tracks the number of swing states in U.S. presidential elections from 1960 to 2020, where swing states are defined as those decided by a margin of 3% or less. The trend reveals the gradual decline in the number of competitive states over time, reflecting broader shifts in the polarization of the U.S. electorate.
These two plots complement each other by showcasing the variation in electoral margins of victory across U.S. states over time, but from different perspectives.
The heatmap offers a year-by-year view, with darker shades representing closer races and lighter shades indicating less competitive elections. It highlights key battleground states like Wisconsin and Michigan, solidly partisan states like Wyoming and Massachusetts, and shifting dynamics in states such as Virginia and Georgia.
The box plot summarizes the range of margins in each state across years, with wider plots in states like Florida indicating fluctuating competitiveness, and narrower ones in states like Wyoming showing consistent partisan loyalty. Color-coded election years reveal trends, such as smaller margins in recent elections for Georgia and Arizona, emphasizing their emergence as swing states.
Together, these visualizations reveal the balance between stability in some states and evolving competitiveness in others, reflecting broader trends in political polarization and demographic shifts.
The techniques and visualizations showcased in this blog illustrate how combining datasets with advanced tools like hvPlot, HoloViews, Panel, and Anaconda Notebooks can uncover meaningful patterns and drive impactful narratives. While the focus here has been on U.S. election data, these methods have broad applications for businesses and organizations.
Whether navigating competitive markets or analyzing team performance, visual tools like Sankey diagrams, heatmaps, and temporal plots help stakeholders see the bigger picture. By adopting these techniques, your organization can elevate its data analysis capabilities, enhance collaboration, and turn raw information into a strategic advantage.
Learn more about how Anaconda inspires innovation through data science and AI on our website.
Talk to one of our experts to find solutions for your AI journey.