Skip to content Skip to sidebar Skip to footer

Matplotlib From Time Series Data Frame

Say I have a data frame like this: from pandas import DataFrame example = {'year_month': [201801,201802,201803,201801,201802,201803], 'store_id': [101,101,101,102,102,102

Solution 1:

import pandas as pd
df = pd.DataFrame(example)
df.year_month = pd.to_datetime(df.year_month, format='%Y%m', exact=True)
df.set_index('year_month', drop=True, inplace=True)

enter image description here

for x in df.store_id.unique():
    df[['tot_employees', 'hrs_per_employee']][df.store_id == x].plot(title=f'Store ID: {x}')

enter image description here

Using only df.groupby

df.groupby('store_id').plot(y=['tot_employees', 'hrs_per_employee'])

Post a Comment for "Matplotlib From Time Series Data Frame"