python - Python:使用 pandas 读取 HTML 表格并使用 matplotlib 绘图
问题描述
所以我已经阅读了一个 HTML 表格,read_html
并将其存储在一个 DataFrame 中。但是当我尝试绘制它回复的 DF 时Empty 'DataFrame' : no numeric data to plot
,我尝试将数据类型从字符串转换为浮点数或整数,但出现“无法转换为浮点数”的错误。
import pandas as pd
import datetime
import matplotlib.pyplot as plt
from matplotlib import style
style.use('ggplot')
# read data and create a df, it will take all page tables
df = pd.read_html('https://money.cnn.com/data/us_markets/')
# Take the first read table only
df = df[0]
# Set the first column as the index
df.set_index(0, inplace=True)
df.plot()
plt.show()
解决方案
推荐阅读
- f# - 在 F# 中使用 %A 格式时是否可以配置显示的列表项的数量?
- c - 在 const 表达式中声明指向结构的指针
- nuxt.js - 似乎无法让基于动态文件系统的路由与 Nuxt.js 一起使用
- javascript - 如何手动修改 Unix TimeStamp 使其比 UTC 晚 5 小时?
- python - 如何计算列表中特定项目的数量?Python3
- python - 我如何使用另一个 CSV 名称列表搜索 CSV 并在它使用 python 找到特定单词时返回
- angular - 如何在 HTML 中声明指向默认插座中路由的链接,在 Angular 中保留命名插座中的路由
- excel - Excel宏根据匹配两个值(行/列)查找单元格并替换单元格中的值
- python - 发生异常:KeyError
- react-native - 反应原生 | 转发到下一个输入