I am working with a dataframe where the index is a datetime object (time series) and the data column is numeric.
My goal is to group the data day by day and draw a boxplot from each of them in order to obtain different statistical metrics.
I think I already have this part thanks to the functions of Pandas
, groupby()
and Grouper()
.
groups = df2.groupby(pd.Grouper(freq='D'))
What I would like is to graph these results.
Independently graphing each of the days in a boxplot , I have succeeded.
groups.boxplot(figsize= (15,25), layout = (nrows, ncols))
plt.show()
I get the following (there are more graphs because they are several months but it is already understood):
To say of these graphs, that I get the time 00:00:00 in the title that I don't like and I would like to remove it, but hey, it's a lesser evil.
The important thing comes now, plotting individually is fine, but I would like to plot all the boxplots in a single plot to be able to better observe the behavior of the data.
I have come to get this,
With this code,
groups = df1.groupby(pd.Grouper(freq='D'))
data = pd.DataFrame(pd.concat([pd.DataFrame(x[1].values) for x in groups], axis=1))
data.boxplot(figsize=(20,5))
plt.show()
But apart from the fact that it makes my life feel complicated, the most important thing is that the X axis has zeros and not the date. So, can someone help me to make the dates come out (vertical I guess)? Does anyone know how to make this simpler?
NOTE: I know that I lose the date when doing x[1].values
it but I don't know how to solve it.
I leave an example of how my dataframe is :
Temperature
Datetime
2018-08-07 11:00:31 6.3
2018-08-07 11:10:31 11.4
2018-08-07 11:20:31 12.0
2018-08-07 11:30:31 13.7
2018-08-07 11:40:31 15.6
2018-08-07 11:50:31 13.6
2018-08-07 12:00:31 12.2
2018-08-07 12:10:31 11.2
2018-08-07 12:20:31 11.6
2018-08-07 12:30:31 12.4
2018-08-07 12:40:31 13.4
2018-08-07 12:50:31 13.2
2018-08-07 13:00:31 12.4
2018-08-07 13:10:31 11.7
2018-08-07 13:20:31 12.1
2018-08-07 13:30:31 11.8
2018-08-07 13:40:31 11.5
2018-08-07 13:50:31 10.9
2018-08-07 14:00:31 10.6
2018-08-07 14:10:31 10.4
2018-08-07 14:20:31 9.6
2018-08-07 14:30:31 9.0
2018-08-07 14:40:31 8.6
2018-08-07 14:50:31 8.1
2018-08-07 15:00:31 7.7
2018-08-07 15:10:31 7.3
2018-08-07 15:20:31 7.3
2018-08-07 15:30:31 8.8
2018-08-07 15:40:31 10.0
2018-08-07 15:50:31 11.3
2018-08-07 16:00:31 11.8
2018-08-07 16:10:31 12.3
2018-08-07 16:20:31 12.9
2018-08-07 16:30:31 13.2
2018-08-07 16:40:31 12.1
2018-08-07 16:50:31 11.1
2018-08-07 17:00:31 10.3
2018-08-07 17:10:31 9.6
2018-08-07 17:20:31 9.4
2018-08-07 17:30:31 8.7
2018-08-07 17:40:31 9.0
2018-08-07 17:50:31 8.3
2018-08-07 18:00:31 7.7
2018-08-07 18:10:31 6.8
2018-08-07 18:20:31 6.4
2018-08-07 18:30:31 5.8
2018-08-07 18:40:31 5.3
2018-08-07 18:50:31 5.2
2018-08-07 19:00:31 5.7
2018-08-07 19:10:31 6.8
Thank you very much!!