Adding new column to existing DataFrame in Python pandas

后端 未结 25 1296
你的背包
你的背包 2020-11-22 01:15

I have the following indexed DataFrame with named columns and rows not- continuous numbers:

          a         b         c         d
2  0.671399  0.101208 -         


        
25条回答
  •  梦谈多话
    2020-11-22 01:40

    One thing to note, though, is that if you do

    df1['e'] = Series(np.random.randn(sLength), index=df1.index)
    

    this will effectively be a left join on the df1.index. So if you want to have an outer join effect, my probably imperfect solution is to create a dataframe with index values covering the universe of your data, and then use the code above. For example,

    data = pd.DataFrame(index=all_possible_values)
    df1['e'] = Series(np.random.randn(sLength), index=df1.index)
    

提交回复
热议问题