0

I am trying to delete the column of a pandas dataframe and I get the following error: ValueError: labels [' 5'] not contained in axis. However my print df.columns returnsInt64Index([0, 1, 2, 3, 4, 5, 6], dtype='int64'). See bellow the code as well:

df = pd.read_csv(StringIO(data),skiprows=186,sep=";",header=None)
#df.drop(' 5', inplace=True)
b= df.columns.tolist()
print df.columns
Andrei Cozma
  • 950
  • 3
  • 9
  • 14

1 Answers1

-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  
karel
  • 5,489
  • 46
  • 45
  • 50
amit rai
  • 5
  • 2
  • 4
  • 4
    Yes, please accept my apology, I missed that. However, you could improve the answer by explaining what OP misunderstood about the syntax and its meanings, if you do that in prose, you could prevent others from also making my mistake. (The downvote is not by me by the way.) – Yunnosch Mar 23 '19 at 08:21