How to divide the value of pandas columns by the other column

后端 未结 1 828
情深已故
情深已故 2020-12-13 15:18

I have a dataframe:

>>> dt
                   COL000   COL001   QT
STK_ID  RPT_Date                       
STK000  20120331   2.6151   2.1467    1
          


        
相关标签:
1条回答
  • 2020-12-13 15:48

    The / operator for dv seems equal to div with default axis "columns". Set the axis to "index", then it'll work.

    df = df.div(df.QT, axis='index')
    

    Another tricky way is to transpose it first, divide it, and then transpose back:

    df = (df.T / df.QT).T
    
    0 讨论(0)
提交回复
热议问题