0
votes

How to group by a given frequency let say Hourly for different dates, and create a set of box plot for one column in a time series data set ?

A similar problem and solution is below. But the below would group hourly data with regards less of date. But the ask over here is, let say we have 10 day data , one Box plot for each day's each hour. Hence we need 10 * 24 Box Plots in single frame. Oder needs to be maintined as Day_1 Hour 1, Day_1 Hour 2 , .. Day 10 Hour 24

Box plot of hourly data in Time Series Python

range = pd.date_range('2015-01-01', '2015-01-10', freq='1min')
df = pd.DataFrame(index = range)

# Average speed in miles per hour
df['speed'] = np.random.randint(low=0, high=60, size=len(df.index))
# Distance in miles (speed * 0.5 hours)
df['distance'] = df['speed'] * 0.25 
# Cumulative distance travelled
df['cumulative_distance'] = df.distance.cumsum()
df.head()

sns.boxplot(x=df.index.hour, y=df.speed)
1
You say you have 10 days of data, but your sample has 365 days :-).Quang Hoang
Thanks for catching and sorry for the mistake, I edited now.user2458922

1 Answers

1
votes

Just add hue:

fig,ax=plt.subplots(figsize=(30,8))
sns.boxplot(x=df.index.hour, y=df.speed, hue=df.index.day, ax=ax)

Output:

enter image description here