I want to plot changes in monthly values from dataset spanning over few years with matplot.pylib, pandas

It is much easier if you split Year/month columns to separate series for each year

import pandas as pd 
import matplotlib.pyplot as plt

fig, axes = plt.subplots(figsize=(6,4))

df = pd.read_csv("data.csv")
df2 = pd.pivot_table(df, index="Month", columns=["Year"])
df2 = df2.reindex(['January', 'February', 'March', 'April', 'May', 'July', 'August', 'September', 'October', 'November', 'December'])
df2.plot(ax=axes)
fig.savefig("plot.png")

your plots

Leave a Comment

tech