0

The dataframe has NaN values. These cells can be filled in with the first actual value in the cells above them. Is this possible? To fill in these values while iterating the rows and say, if cell is NaN, use the above cell value, until next cell down has anything but NaN, then stop filling in and move on until another NaN is encountered.

The results here would be the column df['Line'] would have ['A', 'A', 'A', 'B'] and df['Generation'] would have ['2020A', '2020B', '2020B', '2020A'].

Line Generation SNP-1 SNP-2 SNP-3
A 2020A A A A
NaN 2020B A A A
NaN NaN A A A
B 2020A A A A
1
  • 1
    df.ffill() should do the trick Commented Apr 17, 2022 at 0:11

1 Answer 1

2

The docs here show how to do it:

df.fillna(method="ffill") 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.