I have a dataframe that looks like this.
import pandas as pd
# Intitialise data of lists
data = [{'Month': '2020-01-01', 'Expense':1000, 'Revenue':5000, 'Building':'Stadium'},
{'Month': '2020-02-01', 'Expense':3000, 'Revenue':4000, 'Building':'Stadium'},
{'Month': '2020-03-01', 'Expense':7000, 'Revenue':5000, 'Building':'Stadium'},
{'Month': '2020-04-01', 'Expense':3000, 'Revenue':4000, 'Building':'Stadium'},
{'Month': '2020-01-01', 'Expense':5000, 'Revenue':6000, 'Building':'Casino'},
{'Month': '2020-02-01', 'Expense':5000, 'Revenue':4000, 'Building':'Casino'},
{'Month': '2020-03-01', 'Expense':5000, 'Revenue':9000, 'Building':'Casino'},
{'Month': '2020-04-01', 'Expense':6000, 'Revenue':10000, 'Building':'Casino'}]
df = pd.DataFrame(data)
df
How can I create a loop to iterate over all 'groups' of places? A group is Stadium, Casino, etc. I'm trying to get a time series of revenue and expense data, either stacked with on top of one the other, or one next to the other. I took a crack at it and came up with this hackey-code, but of course it doesn't work, or I wouldn't be asking my question here.
import matplotlib.pyplot as plt
fig, axes = plt.subplots(1, figsize=(12,3))
grouped = df.groupby('Building')
for i, group in grouped:
#print(i)
plt.figure()
df.loc['Month'].hist(column='Month',
bins=10,
ax=axes[i],
sharey=True)
axes[i].set_title('Year in {0}'.format())
axes[i].set_xlabel('Value')
axes[i].set_ylabel('Count')
plt.show()
plt.show()