-2

For example, I have a dataframe which looks like this:

enter image description here

The wanted result is:

enter image description here

What should I do with pandas?

FunPlus
  • 51
  • 3
  • Does this answer your question? [How to drop rows of Pandas DataFrame whose value in a certain column is NaN](https://stackoverflow.com/questions/13413590/how-to-drop-rows-of-pandas-dataframe-whose-value-in-a-certain-column-is-nan) – mozway Aug 01 '21 at 05:02
  • `df.ffill().dropna(subset=['age'])` – ThePyGuy Aug 01 '21 at 06:27

1 Answers1

0

Use a combination of dropna and fillna:

df=df.dropna(subset=['age']).fillna({'champions':1})

or, if you want to fill the values from the previous rows, use ffill:

df=df.dropna(subset=['age']).ffill()
Anurag Dabas
  • 23,002
  • 8
  • 19
  • 34
mozway
  • 81,317
  • 8
  • 19
  • 49