[英]Drop first row when index doesn't start at 0
I want to drop the first row of a dataframe subset<\/code> which is a subset of the main dataframe
main<\/code> .
我想删除作为主数据帧
main<\/code>子集的数据帧
subset<\/code>的第一行。
The first row of the dataframe has
index = 31<\/code> , so when I try dropping the first row I get the following error:
数据框的第一行具有
index = 31<\/code> ,因此当我尝试删除第一行时,出现以下错误:
>>> subset.drop(0, axis=1)
KeyError: '[0] not found in axis'
Simpliest is select all rows without first by position:最简单的是选择所有行而不首先按位置:
df = df.iloc[1:]
df = df if df.index[0] == 0 else df.iloc[1:]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.