【发布时间】:2019-01-27 01:23:11
【问题描述】:
我有一个数据框,我使用 groupby 来获取下表
time_groups=time_data.groupby('time_binned').mean()
time_groups
然后我尝试构建一个条形图来显示“状态”列结果, 但我收到错误 TypeError: unsupported operand type(s) for -: 'str' and 'float'
plt.bar(time_groups.index.astype(str),100*time_groups['Status'])
【问题讨论】:
-
我认为你不应该将字符串作为第一个参数传递给
plt.bar。而是使用range(len(time_groups.index))之类的东西,稍后通过plt.xticks调整标签。 -
time_groups[['status']].plot.bar()?