【发布时间】:2020-08-09 06:44:40
【问题描述】:
我正在尝试为一个项目整理一些社区数据,但我不太明白我做错了什么。
import requests
import lxml.html as lh
import pandas as pd
data = pd.read_html('https://en.wikipedia.org/wiki/List_of_postal_codes_of_Canada:_M')[0]
data.head() #Works
torsort = data[ (data['Borough'] == 'Not assigned') & (data['Neighborhood'] == 'NaN') ].index
data.drop(indexNames , inplace=True)
torsort.head() #Does not work
错误:AttributeError:“Int64Index”对象没有属性“head”
我不明白发生了什么以及为什么我看不到这个新数据帧的标题。
我能否对此进行解释,以及如何理解并继续验证我的数据过滤是否有效?
谢谢!
- 我刚刚意识到一个错误,我在 data.drop 上输入了 indexNames 而不是 torsort,但我仍然没有提取数据。
【问题讨论】:
-
最后不应该是
data.head()吗? -
正如错误提示的那样,
torsort是一个“Int64Index”类型的对象,而不是一个数据框。
标签: python pandas dataframe web-scraping header