How to delete carriage return from Pandas Headers when reading an excel file
Question:
I would like to read excel function in pandas and remove carriage returns found in the headers.
I have found multiple answers pointing out how to remove them in the data but not specifically in the headers.
I have tried a few things, see below, but not working. Any advice appreciated thanks.
df1 = pd.read_excel('S:/DataToClean.xlsm',skiprows=1)
Answers:
You can use rename
:
df1 = (pd.read_excel('S:/DataToClean.xlsm',skiprows=1)
.rename(columns=lambda x: x.strip()))
# Or simply:
df1.colums = df1.columns.str.strip()
I would like to read excel function in pandas and remove carriage returns found in the headers.
I have found multiple answers pointing out how to remove them in the data but not specifically in the headers.
I have tried a few things, see below, but not working. Any advice appreciated thanks.
df1 = pd.read_excel('S:/DataToClean.xlsm',skiprows=1)
You can use rename
:
df1 = (pd.read_excel('S:/DataToClean.xlsm',skiprows=1)
.rename(columns=lambda x: x.strip()))
# Or simply:
df1.colums = df1.columns.str.strip()