How to add data from one dataframe to another using Pandas transpose?

前端 未结 3 1000
没有蜡笔的小新
没有蜡笔的小新 2021-01-21 03:56

Objective: to fill in one dataframe with another using transpose

df = pd.DataFrame({\'Attributes\': [\'love\', \'family\',\'tech\']})
df.T
         


        
3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-21 04:28

    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
    

提交回复
热议问题