Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

replace column names from one df with the rows from the other df

df1:

word merged
green positive_green
green energy positive_green_energy
jets negative_jets
green hydrogen positive_green_hydrogen
renewable energy positive_renewable_energy

df2:

column1 column2 green green energy jets green hydrogen renewable energy
xx xx xx xx xx xx xx

I would like to replace columns’ names in the df2 to the ones from df1 (rows from df1 matching columns with df2 and replace)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use DataFrame.rename with dictionary:

df2 = df2.rename(columns=dict(zip(df1.word, df1.merged)))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading