python-3.x - 如何解决 TypeError:'No Numeric Data to Plot',当 Python 中存在数值数据时
问题描述
我有以下数据框,我想从中创建 Reputation vs Views 的线图,但是尽管 2 列的两种数据类型都显示它们是整数,但我得到了一个错误。请建议我如何纠正它。
DataFrame(原始有更多的行和列)
Id Reputation Views UpVotes DownVotes AccountId ProfileImageUrl
-1 1 0 21001 27468 -1 NaN
1 21228 25360 1052 90 36500 NaN
线图代码
df_users.plot(kind='line',x='Reputation',y='Views')
错误
> TypeError Traceback (most recent call
> last) <ipython-input-16-bbf2a427a767> in <module>()
> ----> 1 df_users.plot(kind='line',x='Reputation',y='Views')
>
> 3 frames
> /usr/local/lib/python3.6/dist-packages/pandas/plotting/_matplotlib/core.py
> in _compute_plot_data(self)
> 408 # no non-numeric frames or series allowed
> 409 if is_empty:
> --> 410 raise TypeError("no numeric data to plot")
> 411
> 412 # GH25587: cast ExtensionArray of pandas (IntegerArray, etc.) to
>
> TypeError: no numeric data to plot
解决方案
以下代码回答了我的问题:
df_users[['Views', 'Reputation']] = df_users[['Views','Reputation']].apply(pd.to_numeric)
推荐阅读
- python - 我想让这段代码更短,这可能吗?
- html - 关于使用@media print 时的 Firefox 与 Chrome 打印到 pdf 工具
- docker - Docker compose - 使用 localhost 的容器之间的连接
- jquery - 使用 jQuery 从文档流中删除单选按钮和标签
- python - django fooloop 计数器在新页面中重新启动
- flutter - Flutter的invokeMethod回调是否在App处于后台状态时运行?
- sql-server - 从 SQL Server 调用时,可以传递 Oracle 存储过程的变量 Ref 游标
- azure - 如何在 Log Analytics 中获取弹性池详细信息
- c++ - PERF_EVENT_IOC_RESET 会影响使用 perf_event_open 的其他应用程序吗?
- java - 为什么Maven找不到org.json JPMS自动模块?