Home > Software engineering >  How to fix columns name of dataframe auto change after use merge or join?
How to fix columns name of dataframe auto change after use merge or join?

Time:04-09

i am using python 3.8, after use join or merge, my dataframe columns auto changes to (column name,) How could i fix it? i tried to use join, merge, and concat but it return the same result :((

here is some images about it

df_temp enter image description here

df_us_ed_songs_pos[0]

enter image description here

both of them have save index is Date. after i use join, it become like this

df_temp.join(df_us_ed_songs_pos[0])

enter image description here

all name columns of df_temp has changed. Anyone know how to fix it? thanks

update: columns name: enter image description here enter image description here enter image description here

hmmm, now i can see that df_temp columns seem wrong, but i checked name_us_ed_songs and it seem normal?

CodePudding user response:

You could update the column names by using a list comprehension and taking off first and last char, like this:

df_temp.columns = [col[1:-1] for col in df_temp.columns]
  • Related