Pandas DataFrame "info" 方法
Pandas DataFrame "info" method
我合并了多个 csv 文件来生成一个数据框。我使用 .info()
方法快速总结我的数据框,并注意到一个关于 Int64Index
的有趣事实。此行显示数据框包含 20,551,697(> 2000 万)个观察结果,但是,0 to 1,924,562
让我感到困惑。
为什么一个包含 2000 万个条目的数据框只有 0 to 1,924,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)
我合并了多个 csv 文件来生成一个数据框。我使用 .info()
方法快速总结我的数据框,并注意到一个关于 Int64Index
的有趣事实。此行显示数据框包含 20,551,697(> 2000 万)个观察结果,但是,0 to 1,924,562
让我感到困惑。
为什么一个包含 2000 万个条目的数据框只有 0 to 1,924,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)