更改

跳转至: 导航搜索

Pandas删除最后一行

删除319字节, 2022年8月28日 (日) 12:11
无编辑摘要
import pandas as pdimport numpy as np Pandas可以使用3种方法删除DataFrame的最后1行。 1.使用iloc,具体语法为:df = df = pd.DataFrame({ 'Quantity'iloc[: { 0: 50, -1: 50, 2: 70,] 3: 50, 4[[File: 80, 5: 100, 6: 30, 7: 106 }, 'Product_Names': { 0: 'Mosuse', 1: 'Keyboard', 2: 'Headphones', 3: 'CPU', 4: 'Flash Drives', 5: 'Tablets', 6: 'Android Box', 7: 'LCD' }, 'Product_Prices': { 0: 100, 1: 70, 2: 150, 3: 1500, 4: 70, 5: 1700, 6: 2500, 7: 1600 },})PandasDelLast1.png]]
2.使用drop,具体语法为:df.drop(index=df.index[-1],axis=0,inplace=True)
[[File:PandasDelLast2.png]]
3.使用head,具体语法为:df = df.drop([lenhead(df)-1],inplace=True) #请勿使用df.drop(shape[0] -1],inplace=True)print("df",df)[[File:PandasDelLast3.png]]
1,138
个编辑

导航菜单