Divide DataFrame by first row

前端 未结 2 781
生来不讨喜
生来不讨喜 2021-02-05 21:22

I have checked the documentation. I don\'t understand the way to index a Pandas DataFrame.

I would like to divide a DataFrame of stock prices by their respective initial

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-05 22:12

    In [193]: df
    Out[193]:
       A  B  C  D
    a  1  8  9  1
    b  5  4  3  6
    c  4  6  1  3
    d  1  0  2  9
    
    In [194]: df.divide(df.ix[0] / 100)
    Out[194]:
         A    B           C    D
    a  100  100  100.000000  100
    b  500   50   33.333333  600
    c  400   75   11.111111  300
    d  100    0   22.222222  900
    

提交回复
热议问题