Search code examples
pythonpython-3.xdataframemultiple-columns

How to access columns in a dataframe having name with special character


I have a dataframe with column names which contains special characters like

Date    
('Date','') 
('Max_Bid_Price', 'ALBAN')  

The problem is when i am trying to drop ('Date','') columns it is throwing error.

I tried

df["('Date','')"]   # not able to find the label
df["\(\'Date\'\,\'\'\)"] # not able to find the label

but when i tried

data.columns[1] # i got the column value as output
data.drop(data.columns[1],axis=0) # but it still throws an error: "labels [('Date', '')] not contained in axis"

Can anyone help me how to access those columns with name(since i have to do operations on it) and also drop those columns:


Solution

  • You can use raw string literals:

    df.drop(r"('Date','')", axis=1)