How to group by a given frequency let say Hourly f

2019-08-26 00:56发布

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条回答
老娘就宠你
2楼-- · 2019-08-26 01:35

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

查看更多
登录 后发表回答