Python 3 Pandas - Column with extra \ n \ t \ t \ t \ t \ t

I have dataframe from an .xls spreadsheet, and I type columns print(df.columns.values)

, and the output contains a column with the name: Poll Responses\n\t\t\t\t\t

.

I am looking in an excel sheet and in the cell column header, there are no extra spaces or tabs.

So, in order to get data from these columns I have to use print(df['Poll Responses\n\t\t\t\t\t'])

Is this the case or am I doing something wrong?

+3


source to share


1 answer


Use .str.strip

:

df.columns = df.columns.str.strip()

      



This will separate spaces for the column headings in the data area.

+4


source







All Articles