1

I have a dataframe:

sn ID Amount
0 10 3836.68
1 1087.63
2 70
3 20 2863.56

I want something like:

sn ID Amount
0 10 3836.68
1 70 1087.63
3 20 2863.56
0

1 Answer 1

2

Replace empty strings by NaN (no need if empty values are already NaN), then backward fill the rows, and finally drop duplicates on ID column:

>>> df.replace('', np.nan).bfill(axis=0).drop_duplicates(['ID'])

   sn    ID   Amount
0   0  10.0  3836.68
1   1  70.0  1087.63
3   3  20.0  2863.56
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.