如何解决Pandas DataFrame“信息”方法
我将多个 csv 文件组合起来生成一个数据框。我使用 .info()
方法来快速总结我的数据框,并注意到关于 Int64Index
的一个有趣事实。此行显示数据框包含 20,551,697(> 2000 万)个观测值,但是,0 to 1,924,562
让我感到困惑。
为什么一个包含 2000 万个条目的数据框只有来自 0 to 1,562
的索引?
<class 'pandas.core.frame.DataFrame'>
Int64Index: 20551697 entries,0 to 1924562
Data columns (total 15 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 tripduration 20551697 non-null int64
1 starttime 20551697 non-null object
2 stoptime 20551697 non-null object
3 start station id 20551517 non-null float64
4 start station name 20551517 non-null object
5 start station latitude 20551697 non-null float64
6 start station longitude 20551697 non-null float64
7 end station id 20551517 non-null float64
8 end station name 20551517 non-null object
9 end station latitude 20551697 non-null float64
10 end station longitude 20551697 non-null float64
11 bikeid 20551697 non-null int64
12 usertype 20551697 non-null object
13 birth year 20551697 non-null int64
14 gender 20551697 non-null int64
dtypes: float64(6),int64(4),object(5)
memory usage: 2.4+ GB
解决方法
没有默认的 RangeIndex
,我认为原因是索引值重复。
您可以通过Index.has_duplicates
查看:
print (df.index.has_duplicates)
要删除重复项,请使用:
df = df.reset_index(drop=True)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。