Adding new column to existing DataFrame in Python pandas

后端 未结 25 1248
你的背包
你的背包 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:46

    Doing this directly via NumPy will be the most efficient:

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

    Note my original (very old) suggestion was to use map (which is much slower):

    df1['e'] = df1['a'].map(lambda x: np.random.random())
    

提交回复
热议问题