Objective: to fill in one dataframe with another using transpose
df = pd.DataFrame({'Attributes': ['love', 'family','tech']})
df.T
Produces this output:
0 1 2
Attributes love family tech
Secondarily, I have another dataframe that is empty:
data = pd.DataFrame(columns = ['Attribute_01',
'Attribute_02',
'Attribute_03']
I would like to bring the two dataframes together to produce the following:
Attribute_01 Attribute_02 Attribute_03
love family tech
Setup
df
Attributes
0 love
1 family
2 tech
Option 1
rename
df.T.rename(dict(enumerate(data.columns)), axis=1)
Attribute_01 Attribute_02 Attribute_03
Attributes love family tech
Option 2
set_index
df.set_index(data.columns).T
Attribute_01 Attribute_02 Attribute_03
Attributes love family tech
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With