python - 使用 groupby 绘制 pandas 数据框 - TypeError:没有要绘制的数字数据
问题描述
我在使用 matplotlib 在 python 中绘制 groupby 数据时遇到问题,作为 python 新手,我将不胜感激。
目的:按时间段(x 轴)绘制英格兰(y 轴)按地区分组的总翻倒事件。
首先,我对我的数据进行子集化:
##Total Per Region
TotalPerRegion=data[(data['LA_Name']=='Total') & (data['Region'] != 'TotalEngland')]
转换数据并按区域分组
TotalPerRegion=TotalPerRegion.groupby(['Year','Region'])['Total_Incidents'].sum().unstack(level='Region')
OutputRegion East East Midlands London North East North West South East \
Year
2012-13 56484 40059 231894 56748 105201 66710
2013-14 63829 44747 327484 50467 113596 70029
2014-15 68373 48946 367075 50837 108536 74484
2015-16 69461 50694 320137 48067 117529 69315
2016-17 75447 60969 349878 53005 128193 79911
2017-18 72832 68470 284250 62037 111920 79307
2018-19 67792 69237 324261 63646 112069 83752
Region South West Total England West Midlands Yorkshire and The Humber
Year
2012-13 45182 714637 46425 57536
2013-14 53433 857655 56880 67391
2014-15 56166 905604 56895 66051
2015-16 34390 941896 56466 68883
2016-17 44745 1011199 63806 76545
2017-18 56563 997553 59593 86697
2018-19 59334 1072431 65379 97649
然后尝试绘制数据:
fig, ax = plt.subplots()
TotalPerRegion.plot()
然后出现此错误:
raise TypeError("no numeric data to plot")
TypeError: no numeric data to plot
任何人都可以提供任何帮助来解决问题吗?谢谢。
解决方案
推荐阅读
- python - 时间序列数据的滑动窗口训练/测试拆分
- html - 如何让我的框 3 与框 2 的右侧对齐?
- nginx - 位置 nginx 中的反向代理
- python - 如何在 Django 2.2 中列出多个 slug 而不会出错?
- c++ - 关于为指向在运行时确定的许多结构之一的指针构建类的建议
- android - AndroidManifest.xml 无法解析 android:label="@string/app_name"
- sql - 无法弄清楚如何将 sql 表重新连接在一起以创建报告
- python - 如何从熊猫中的日期时间中删除日期
- firebase - 带有 Flutter 的 Firebase 中的唯一用户名
- c - malloc 之后的分段错误字符**