Merge dataframes in a dictionary

前端 未结 1 916
灰色年华
灰色年华 2020-12-05 07:55

Say I have an dictionary of dataframes:

  {\'df1\': name         color    type
          Apple        Yellow   Fruit,
   \'df2\': name         color    type
         


        
相关标签:
1条回答
  • 2020-12-05 08:27

    You can just pass the dict direct and access the values attribute to concat:

    In [233]:
    
    d
    Out[233]:
    {'df1':     name         color    type
     0  Apple        Yellow   Fruit, 'df2':     name         color    type
     0  Banana       Red      Fruit, 'df3':     name         color    type
     0  Chocolate    Brown    Sweet}
    In [234]:
    
    pd.concat(d.values(), ignore_index=True)
    Out[234]:
        name         color    type
    0  Banana       Red      Fruit
    1  Apple        Yellow   Fruit
    2  Chocolate    Brown    Sweet
    

    This assumes that you are just looking to concatenate all the dfs, if you are going to merge then you need to explain what the merge criteria is

    0 讨论(0)
提交回复
热议问题