Reputation: 37
So lets say I have a column in my csv file named "how are you" how can I read the contents of this column? Right now I am changing the column name in csv file and running this, it works but how can I do it without changing anything in the csv file?
df1 = pd.read_csv('file.csv')
x = df1.howareyou
Upvotes: 2
Views: 1969
Reputation: 345
samutamm's answer definitely works.
However, if you like to access the columns using dot
notation, you can replace the spaces with '_'. e.g:
df.columns = df.columns.str.replace(' ', '_')
df.how_are_you
Upvotes: 0