0

I have a df in which I first split col1 at "-". This results "None" values in col3 if delimiter does not exist in the col1.

Now, if col3 is "None", I want to replace it with col2 values (inplace replacement)

#df
 col1 col2 col3
45-65 45 65   
   56 56 None

#desired df
 col1 col2 col3
45-65 45 65   
   55 55 55

How can I do this in pandas.

1 Answer 1

1
df = df.ffill(axis=1)
print(df)

Output:

    col1 col2 col3
0  45-65   45   65
1     56   56   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.