pandas - AttributeError:“系列”对象没有属性“to_numeric”
问题描述
我正在尝试按值对数据框进行排序。得到一个 AttributeError:“系列”对象没有属性“to_numeric”。版本'0.20.3',所以数字应该可以工作,但不是。请帮忙。
import pandas as pd
tables = pd.read_html("https://www.sec.gov/Archives/edgar/data/949012/000156761919015285/xslForm13F_X01/form13fInfoTable.xml")
len(tables)
ren=tables[3]
ren.drop(ren.index[[0,1,2]], inplace=True)
ren.to_numeric(ren[3], errors='coerce')
#ren[3].convert_objects(convert_numeric=True)
ren.sort_values(by=[3],ascending=False)
解决方案
import pandas as pd
tables = pd.read_html("https://www.sec.gov/Archives/edgar/data/949012/000156761919015285/xslForm13F_X01/form13fInfoTable.xml")
len(tables)
ren=tables[3]
ren.drop(ren.index[[0,1,2]], inplace=True)
ren[3] = pd.to_numeric(ren[3], errors='coerce')
ren.sort_values([3],ascending=False, inplace=True)
ren
0 1 2 3 ...
101 JPMorgan COM 46625h100 48532 ...
44 Cisco COM 17275r102 47376 ...
204 Waste Management COM 94106L109 41558 ...
117 Microsoft COM 594918104 37492 ...
99 Johnson & Johnson COM 478160104 31491 ...
推荐阅读
- android - 媒体播放器在后台
- mapbox - 仅使用 fetch API 从 mapbox 获取建筑物多边形点
- python-3.x - 在 IBM SPSS Statistics 版本 26 中安装或导入 Pandas
- firebase - 新创建的 Firebase 函数引发 UNAUTHENTICATED 错误
- reactjs - 如何在使用 reactjs 提交方法时一次发布 2 个 API?
- android - 使用自定义分辨率录制 Camera2 视频?
- reactjs - 在 404 上反应无限循环
- python - Imdbpy 获取家长指南
- c++ - 无法捕获异常 std::stoi
- c++ - 为什么它会打印出意外的值?