0

I have this dataframe

enter image description here

My goal is to fill the Nan values in the 3rd and 4th column with the non-Nan data in each column. Tried shift(-5) but didn't get it to work. Any thoughts?

1
  • df.iloc[:5, [2, 3]] = df.iloc[5:, [2, 3]].to_numpy()? Commented Apr 5, 2021 at 19:41

1 Answer 1

1

Use bfill:

df[['col3','col4']] = df[['col3','col4']].bfill()

OR:

df[['col3','col4']] = df[['col3','col4']].fillna(method='bfill')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.