I have a pandas DataFrame that contains a value that was logged every few minutes.
import pandas as pd
import numpy as np
df = pd.DataFrame()
df['Time'] = pd.date_range("2018-01-01", periods=1000, freq="5Min")
df['Value'] = np.random.randint(1, 6, df.shape[0])
Now I want to make a boxplot showing the distribution per day. Normally, I would use resample
or groupby
, but I have the problem to feed the groups back into seaborn for the boxplot or to perform some other statistics.
Right now I use a very ugly form to return the groups back into a DataFrame and flip it to have the days as columns:
daily = df.groupby(pd.Grouper(key='Time', freq='1D'))
df_days = daily['Value'].apply(lambda df: df.reset_index(drop=True)).unstack().transpose()
df_days
can than be fed into seaborn.boxplot to generate the whisker-plots.
Is there an easier way to get the DataFrame df_days
?
Thanks