删除pandas dataframe列

时间:2016-10-17 06:44:58

标签: python pandas

我正在尝试删除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

1 个答案:

答案 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