I am trying to create 12 boxplots of panda df's by the column = 'Var' and by = 'plant_name' from my dataframe (df3). I need to create a boxplot for of the column 'Var' and by = 'plant_name" for each of the 12 months of the year Jan - Dec. I have code below that plots 12 plots - one for each month from my list of months =['Jan','Feb','Mar',...'Dec']. However, my code is plotting all the months data in the same boxplot 12 times instead of 12 unique months data from the 'Var' column in df3.
My code:
months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nove','Dec']
for column in months:
plt.figure()
df3.boxplot(by='plant_name',column='Var')
plt.xticks(rotation=90, ha='right')
df3.head(5)
Out[32]:
plant_name month year power_kwh power_kwh_rhs Var
0 BII NEE STIPA 1 1991 11905.826075 14673.281223 -18.9
1 BII NEE STIPA 1 1992 14273.927688 14673.281223 -2.7
2 BII NEE STIPA 1 1993 12559.828360 14673.281223 -14.4
3 BII NEE STIPA 1 1994 14627.635081 14673.281223 -0.3
4 BII NEE STIPA 1 1995 13715.054435 14673.281223 -6.5
and the end of df3 -
Out[33]:
plant_name month year power_kwh power_kwh_rhs Var
2875 VENTOSA 12 2016 45840.068414 48876.289265 -6.2
2876 VENTOSA 12 2017 59288.158871 48876.289265 21.3
2877 VENTOSA 12 2018 44438.768683 48876.289265 -9.1
2878 VENTOSA 12 2019 47002.390188 48876.289265 -3.8
2879 VENTOSA 12 2020 52101.279839 48876.289265 6.6