我正在将一个csv文件读入数据帧,然后我尝试计算数据帧中的行数,但得到了不同的结果。这是我的密码
data_df = pd.read_csv(data_path, header=0)
print(len(data_df.index)) # => 19695182
data_df_grouped = data_df.groupby(["SiteNumber", "WeekNumber", "PG"]).count()
data_df_grouped #-> This will print out the dataframe in jupyter notebook... I got:
但我接着补充说:
data_df_grouped.sum() # And I got:
因此,我可以清楚地看到行数不匹配。原因可能是什么
非常感谢您的帮助
我刚刚发现我的数据帧中有重复的行,因此,上面的
count
后跟sum
就产生了19695182行。此外,打印出len(data_df_grouped.index)
将产生19573194行,因此data_df_grouped.index
将返回唯一的行索引相关问题 更多 >
编程相关推荐