python pandas operations on columns

前端 未结 4 426
北海茫月
北海茫月 2021-02-06 11:52

Hi I would like to know the best way to do operations on columns in python using pandas.

I have a classical database which I have loaded as a dataframe, and I often have

4条回答
  •  余生分开走
    2021-02-06 12:33

    Start with..

    df = pd.DataFrame({'a':randrange(1,10),'b':randrange(10,20),'c':np.random.randn(10)})
    a   b   c
    0   7   12  0.475248
    1   7   12  -1.090855
    2   7   12  -1.227489
    3   7   12  0.163929
    

    end with...

    df.ix[df.A < 1,df.A = df['c'] - df['d']]; df
        a   b   c
    0   7   12  5.000000
    1   7   12  5.000000
    2   7   12  5.000000
    3   7   12  5.000000
    4   7   12  1.813233
    

提交回复
热议问题