price = price 0 111 1 222 2 333 3 444
I want newprice =
price 0 111 1 222/111 2 333/222 3 444/333
Use df.shift with df.fillna:
df.shift
df.fillna
In [1046]: df['new_price'] = df.price.div(df.price.shift()).fillna(df.price) In [1047]: df Out[1047]: price new_price 0 111 111.000000 1 222 2.000000 2 333 1.500000 3 444 1.333333
2.1m questions
2.1m answers
60 comments
57.0k users