Python Charts

Now assume we want plots of all Europe countries at once and we’d like to save these png files:

import pandas as pd

import numpy as np

df = pd.read_excel('europe_cities_by_sunshine.xlsx')

for country in df['Country'].unique().tolist():

sub_df = df[df['Country'].isin([country])]

ax = sub_df.plot(kind='scatter', x='Jan', y='Jul' )

for idx, row in sub_df.iterrows():

ax.annotate(row['City'], (row['Jan'], row['Jul']))

ax.set_title(f'{country} Months By Total Sunshine')

ax.figure.savefig(f'{country}_Scatterplot.png')

Explanation:

Now the main difference is the line with “savefig” which will save the png file for each country in the for loop. So now there will be dozens of new png files in your python directory, each named uniquely for the different countries that are present in the Excel file.