我正在尝试删除pandas数据框的列,并收到以下错误:ValueError: labels [' 5'] not contained in axis
。但是我的print df.columns
会返回Int64Index([0, 1, 2, 3, 4, 5, 6], dtype='int64')
。请参阅下面的代码:
df = pd.read_csv(StringIO(data),skiprows=186,sep=";",header=None)
#df.drop(' 5', inplace=True)
b= df.columns.tolist()
print df.columns
答案 0 :(得分:-1)
df=df.drop(0,axis=1) #to delete/remove single columns
df=df.drop([0,2,3,4,5,6],axis=1) #To delete columns at 0 2,3,4,5,6
df.drop(columns=['B', 'C']) #to Delete columns by name