Stupidly Quick Data Viz Dashboard With GPT-4 And Python That You Have to See
Clever coaxing with GPT4 for a Streamlit data visualization dashboard
GPT-4 assists Python developers to create data visualizations at an insanely fast pace.
GPT-4 can be prompted to create Python code snippets in a modular fashion which greatly simplifies the coding process. With GPT-4, developers can focus on higher-level tasks and analysis, while the LLM takes care of the underlying code complexities.
Utilizing pandas, plotly, folium, and Streamlit, here is a practical example of how GPT-4 can be used to significantly expedite and streamline the Python data visualization development process.
Step 1: Preprocessing the Data
This example will be analyzing a dataset of global greenhouse gas emissions — the dataset can be downloaded from HERE.
We will begin by loading the CSV file and preprocessing the data. This includes replacing the “USA” entry with “United States of America” for the “Country” field (this will match up later with the world-countries.json file that we need to display on a folium map). Also, we can remove the last two sets of data in the CSV — “Global” and “International Transport”.
Prompt for ChatGPT-4: Please give me the Python code to load a CSV file called “global_emissions.csv” and replace any entry for “USA” in the “Country” field with “United States of America”. Remove the records called “Global” and “International Transport” from the Country field.
Response from ChatGPT-4: Certainly, here is the code:
import pandas as pd
# Load the CSV file
emissions_data = pd.read_csv("global_emissions.csv")
# Replace "USA" with "United States of America"
emissions_data["Country"] = emissions_data["Country"].replace("USA", "United States of America")
# Remove records with "Global" and "International Transport" from the Country field
emissions_data = emissions_data[~emissions_data["Country"].isin(["Global", "International Transport"])]
Great, now we have a nice clean data file work with. The file will be saved as “global_emissions.csv” and now we can run this code to create a nice, clean pandas data frame that is ready for the next step!
NOTE: All of the working files generated in this article are available on my GitHub: HERE.
Step 2: Creating Visualizations
With the data all cleaned up, let’s start with two visualizations: a stacked area chart displaying the top 10 countries by total emissions between 1970 and 2020, and a line chart showing the top 10 countries by per-capita emissions during the same period.
Stacked Area Chart
A stacked area chart displays quantitative data over time, where values for different categories are layered on top of each other. Each area represents a part of the whole, showing both individual trends and cumulative totals.
GPT-4 Prompt: Please give me the Python Plotly code for a stacked area chart using Plotly that displays the top 10 countries by total emissions between 1980 and 2020.
GPT-4 Response: Certainly, here is the code:
import pandas as pd
import plotly.graph_objects as go
# Load dataset, filter years, set per country, filter top 10
df = pd.read_csv("global_emissions.csv")
df_filtered = df[(df['Year'] >= 1980) & (df['Year'] <= 2020)]
top_countries = df_filtered.groupby("Country")["Total"].sum().nlargest(10).index.tolist()
df_top10 = df_filtered[df_filtered["Country"].isin(top_countries)]
# Pivot data: rows = Year, columns = Country, values = Total emissions
df_pivot = df_top10.pivot_table(index="Year", columns="Country", values="Total", aggfunc="sum").fillna(0)
# Build stacked area chart
fig = go.Figure()
for country in df_pivot.columns:
fig.add_trace(go.Scatter(
x=df_pivot.index,
y=df_pivot[country],
mode='lines',
stackgroup='one',
name=country
))
fig.update_layout(
title="Top 10 Countries by Total Emissions (1980–2020)",
xaxis_title="Year",
yaxis_title="Total Emissions (Million Metric Tons)",
hovermode="x unified",
legend_title="Country"
)
fig.show()
That is all the Plotly code needed for the stacked area chart.
You can save this file as stacked_area01.py and Run it.
In our default browser, it will look like so:

Beautiful! Stacked area charts are one of my favourite chart styles to look at — especially when they’re used correctly.
This stacked area chart tells a very interesting story — you can clearly see that China has increased emissions drastically since the 1980s and has surpassed the United States. Overall emissions for India are also on the rise.
There is a lot more to think about and discuss, but we must keep moving forward!
Time-Series Line Chart
A time-series line chart displays data points over time using lines to show trends and changes across one or more variables.
GPT-4 Prompt: Write Python code to create a line chart using Plotly that displays the top 10 countries by per-capita emissions between 1970 and 2020.
GPT-4 Response: Certainly, here is the code:
import pandas as pd
import plotly.graph_objects as go
# Load the dataset
df = pd.read_csv("global_emissions.csv")
# Filter for the years 1980–2020, calculate average emissions, top 10 countries
df_filtered = df[(df['Year'] >= 1980) & (df['Year'] <= 2020)]
top_countries_pc = df_filtered.groupby("Country")["Per Capita"].mean().nlargest(10).index.tolist()
df_top10_pc = df_filtered[df_filtered["Country"].isin(top_countries_pc)]
# Pivot the data for line chart plotting
df_pivot_pc = df_top10_pc.pivot_table(index="Year", columns="Country", values="Per Capita", aggfunc="mean").fillna(0)
# Create the Plotly line chart
fig = go.Figure()
for country in df_pivot_pc.columns:
fig.add_trace(go.Scatter(
x=df_pivot_pc.index,
y=df_pivot_pc[country],
mode='lines',
name=country
))
fig.update_layout(
title="Top 10 Countries by Per-Capita Emissions (1980–2020)",
xaxis_title="Year",
yaxis_title="Per-Capita Emissions (Metric Tons per Person)",
legend_title="Country",
hovermode="x unified"
)
fig.show()
That is all the plotly code needed for the stacked area chart.
You can save this file as line_chart01.py and Run it.
In our default browser, it will look like so:
Terrific! Looking a bit closer at the data, it is worth noting the USA has the distinction of being the only country that appears on both charts.
There are a lot more stories to be told here with this data! This modular approach makes it a simple process to revise the prompts to display different visualizations, or to add additional visualizations (for example, heat maps or bar charts).
But let’s move on! Let’s create a Folium map to display the per-capita emissions for each country.
Step 3: Displaying on a Folium Choropleth Map
A choropleth map uses varying color shades to show data values across geographic areas, highlighting regional differences. For our example, we are going to compare across countries.
Now to set the boundaries for each country on a folium map, we need an extra file that contains the boundary coordinates. We can use a file called “world-countries.json”. (Available on my GitHub HERE.
Now we can upload this file to GPT-4 and prompt it for our Folium map code:
Response from ChatGPT-4: Certainly, here is the code:
import pandas as pd
import folium
import json
# Load emissions dataset
df = pd.read_csv("global_emissions.csv")
# Filter for 1980–2020
df_pc = df[(df['Year'] >= 1980) & (df['Year'] <= 2020)]
# Compute average per-capita emissions by country
avg_pc_emissions = df_pc.groupby('Country')['Per Capita'].mean().reset_index()
avg_pc_emissions.columns = ['Country', 'Avg_Per_Capita_Emissions']
# Rename mismatched country name to match GeoJSON
rename_map = {
'USA': 'United States of America',
}
avg_pc_emissions['Country'] = avg_pc_emissions['Country'].replace(rename_map)
# Load GeoJSON for world countries
with open("world-countries.json", "r", encoding="utf-8") as f:
world_geo = json.load(f)
# Create Folium map
m = folium.Map(location=[20, 0], zoom_start=2, tiles="cartodbpositron")
# Add choropleth layer
choropleth = folium.Choropleth(
geo_data=world_geo,
data=avg_pc_emissions,
columns=["Country", "Avg_Per_Capita_Emissions"],
key_on="feature.properties.name",
fill_color="YlOrRd",
fill_opacity=0.7,
line_opacity=0.2,
legend_name="Average Per-Capita Emissions (Metric Tons, 1970–2020)",
nan_fill_color="gray"
).add_to(m)
# Tooltip for country names
folium.GeoJsonTooltip(fields=["name"]).add_to(choropleth.geojson)
# Save to HTML file
m.save("avg_per_capita_emissions_map.html")
This code creates a folium choropleth map (using the built-in Choropleth() function) When we create a folium map, we can specify that the map be saved to an html file (as shown in the last line of code in the above snippet).
You can save this file as folium_choropleth01.py and Run it. The code generates an HTML file that can be viewed in a browser.
The map looks like so:
Awesome! It turns out that Canada and the USA are pretty dark on this map — pretty high emissions per capita over the past 50 years.
Now that we have all 3 pieces to our puzzle, how can we display them all in one interface?? Let’s use Streamlit to do this for us!
Step 4: Integrating Visualizations with Streamlit
Finally, we will integrate the folium map and both charts into a single web application using Streamlit.
Why Streamlit? It lets you display multiple interactive visuals side by side with minimal code, making it ideal for quick, shareable data dashboards in pure Python.
GPT-4 Prompt: Write Python code to create a Streamlit web application that displays the stacked area chart and the line chart side by side and the folium choropleth map below.
GPT-4 Response:
For the sake of brevity, I have not included the code — all the code is in the file streamlit01.py and can be viewed/downloaded on my GitHub HERE.
And that is it — now we can run the Streamlit code (I saved the file as streamlit01.py) from a Terminal (command) prompt:
A Streamlit App is then created and can be accessed (by default) in your browser at the first available port above 8050:

Wait, what?? Is it really that easy to do this? Yup.
This is a very nice looking data visualization providing some very good possibilities for analysis and data storytelling.
Humans are visual creatures — the colors, combined with the volumes and variations over time give us lots to observe and discuss.
Nice work!
In Summary…
GPT-4’s code generating capabilities, particularly for complex data visualizations, has truly transformed the Python coding landscape.
By prompting, we are slashing the time spent on coding dashboards like this — from hours (sometimes even days) down to just a few minutes. This productivity boost lets developers concentrate on the more enjoyable and meaningful aspects of their work, like the analysis and the storytelling of their data.
The focus is then less less about tedious coding tasks and more on high-level creative thinking and problem-solving.
NOTE: all of the code and data files from this article are on my GitHub HERE.