我的数据我这个文件https://drive.google.com/open?id=0B4KXs5bh3CmPWXJkQWhkbzI0WEE如何在python熊猫中使用matplotlib绘制两张图?
#count weekdays 0 to 4
mUserType = np.where(rides['starttime'].dt.dayofweek <= 5, 'Weekend',
'Weekday')
#count hours
mWeekHours = rides['starttime'].dt.hour
#create group by usertype
WeekdayWorkdayResult = rides.groupby([mUserType, mWeekHours,
'usertype']).size().unstack()
WeekdayWorkdayResult
这段代码根据用户类型,即客户和用户
我想用matplotlib绘制这种格式的图形怎么能算周末和工作日的小时一世? Weekday and Weekend Graph
它按小时数和用户类型显示乘车次数。一个情节工作日,第二个周末。包含所有每小时骑
# count trips by date and by hour
ind = pd.DatetimeIndex(rides.starttime)
rides['date'] = ind.date.astype('datetime64')
rides['hour'] = ind.hour
by_hour = rides.pivot_table('tripduration', aggfunc='count',
index=['date', 'hour'],
columns='usertype').fillna(0).reset_index('hour')
# average these counts by weekend
by_hour['weekend'] = (by_hour.index.dayofweek >= 5)
by_hour = by_hour.groupby(['weekend', 'hour']).mean()
by_hour.index.set_levels([['weekday', 'weekend'],
["{0}:00".format(i) for i in range(24)]],
inplace=True);
by_hour.columns.name = None
fig, ax = plt.subplots(1, 2, figsize=(16, 6), sharey=True)
by_hour.loc['weekday'].plot(title='Hourly Rides User Type and Hour',
ax=ax[0])
by_hour.loc['weekend'].plot(title='Weekend Rides by User Type and Hour',
ax=ax[1])
ax[0].set_ylabel('Hourly Rides by User Type');
这里情节线的代码我只得到用户和客户的数据我也想获得的所有图线是指两个子和卡斯特小时总和weekdend和工作日
我想绘制图形,因为我在图片中显示,但无法做 – kiran
你能更明确地知道你试过什么和出了什么问题吗?你的话建议在一张图上的两个图是问题所在。 – doctorlove
我更新了问题 – kiran