Pandas删除最后一行

来自YTYZX有图有真相的百科
跳转至: 导航搜索
Pandas可以使用3种方法删除DataFrame的最后1行。
1.使用iloc,具体语法为:df = df.iloc[:-1 , :]
  

PandasDelLast1.png

2.使用drop,具体语法为:df.drop(index=df.index[-1],axis=0,inplace=True)
  

PandasDelLast2.png

3.使用head,具体语法为:df = df.head(df.shape[0] -1)

PandasDelLast3.png