drop()函数
1 删除前务必指定columns或index,避免出错.
import pandas as pd df = pd.DataFrame({'a':[1,2,3], 'b':[3,4,5], 'c':[5,6,7]}) # 删除列 删除多列是加['a','b'] df.drop(columns='a', inplace=True) print(df) # 删除行 df.drop(index=[1,2], inplace=True) print(df) # b c # 0 3 5 # 1 4 6 # 2 5 7 # b c # 0 3 5
参考:https://www.bbsmax.com/A/Vx5MwBX7zN/
delete()函数
import numpy as np a = [1,2,3] # 0是要删除的元素的索引 a = np.delete(a, 0) print(a)