Skip to content
Advertisement

Drop first nan rows in multiple columns

I have the below df:

JavaScript

I want to structure the data so the first NaN rows are deleted by column.

Resuling df:

JavaScript

I’m essentially trying to shift the column data up by n rows depending on where the data starts for that column, so at the first rows of ID there is always data in at least 1 of the Number columns.

I’ve tried first_row_index but this doesn’t work by individual column

I’ve tried dropna but I can’t find a solution where I’m defining what number of rows to drop per column.

Advertisement

Answer

JavaScript

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement