首页 > 解决方案 > 如何从数据框中排除特定行?

问题描述

我正在关注“统计学习简介”,但在 python 而不是 R 中做所有事情。我试图获取我的数据框并从中排除某些行,然后汇总这些行以获得新值。我的代码似乎没有这样做,我想知道问题可能出在哪里?

当我第二次使用 .describe 函数时,我得到的值完全相同,没有任何变化。我想知道问题是什么。

这是代码:


autoData = pd.read_csv('Auto.csv')

print(autoData.describe()) # Gives all the information. The range, std, mean etc

auto2 = autoData.drop(autoData.iloc[:10, 85:])
print(auto2.describe())``` 

标签: pythonpandasstatistics

解决方案


不要删除这些行,而是对要保留的行进行切片:

auto2 = autoData.iloc[10:,:85]

推荐阅读