Reputation: 1
I have a dataframe valence_data with columns word1, word, word3, word4....
And I have my second dataframe word_data with columns 1, 2, ,3 ,4 ...
How can I replace the columns names in word_data by names from valence_data.
e.g. word_data with columns word1, word, word3, word4....
I am using pandas processing my data.
Thanks
Upvotes: 0
Views: 3048
Reputation: 50
Just do this
import pandas as pd
word_data = pd.DataFrame(word_data,columns=list(valence_data))
But the number of columns in both dataframes should be equal
Upvotes: 0
Reputation: 285
You need to use DataFrame.rename
original_names = ["1", "2", ...]
new_names = ["word1", "word2", ...]
new_columns = dict(zip(original_names, new_names))
df.rename(index=str, columns=new_columns)
Upvotes: 1