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?

拜拜、爱过 提交于 2020-01-06 04:51:07

问题


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:


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:



来源:https://stackoverflow.com/questions/56893658/how-to-group-by-a-given-frequency-let-say-hourly-for-different-dates-and-create

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!