0

i hava pandas.DataFrame like

   a
0  1
1  2
2  3

I want to get the result like

a   resulta
a1   nan
a2   a2 ÷ max([a1,a2])
a3   a3 ÷ max([a1,a2,a3])
a4   a4 ÷ max([a1,a2,a3,a4])
.
.
an   an ÷ max[a1,a2,a3...an]

how can i do?

lzwei
  • 58
  • 5
  • Welcome to Stack Overflow. It is not clear what you are asking. Please provide a [reproducible example](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) and make clear what the expected result should be. – Steele Farnsworth Nov 28 '21 at 16:27

1 Answers1

1

you can use the cummax method of pandas (doc):

df["resulta"] = df["a"] + df["a"].cummax()

if df is

   a
0  1
1  2
2  3
3  2

you would get

   a  resulta
0  1        2
1  2        4
2  3        6
3  2        5
Antoine Redier
  • 395
  • 1
  • 8