I imported an excel table with the original column name as such.
MAS 183 /1095 | OS (NV) |
---|---|
123 | 456 |
Column names appeared with an extra \n at the spaces for one of them and ".1" at the back of both.
MAS 183 /1095.1 | OS\n(NV).1 |
---|---|
123 | 456 |
df.columns = df.columns.str.replace("\n", " ")
df.columns = df.columns.str.replace(".1", "")
Did a string replacement on the column header with the above command and the outcome was weird for column name with numbers. All text column name seems ok.
MAS83 095 | OS (NV) |
---|---|
123 | 456 |
CodePudding user response:
IIUC, you want to make the column names like in the original? Then you could try:
df.columns = df.columns.str.replace("\\n", " ", regex=False).str.split('.').str[0]
Output:
MAS 183 /1095 OS (NV)
0 123 456