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

前端 未结 3 1001
没有蜡笔的小新
没有蜡笔的小新 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:12

    Use .loc accessor to set the first row of data using a listified df['Attributes'].

    data.loc[0] = df['Attributes'].tolist()
    

    Result:

      Attribute_01 Attribute_02 Attribute_03
    0         love       family         tech
    
    0 讨论(0)
  • 2021-01-21 04:19

    I think you just need to change the column name in df1

    df.columns=data.columns
    df
    Out[741]: 
               Attribute_01 Attribute_02 Attribute_03
    Attributes         love       family         tech
    
    0 讨论(0)
  • 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
    
    0 讨论(0)
提交回复
热议问题