0

I have the following dataframe

column1 column1
None value 1
None value 1
None value 1
None value 1
value2 None

Both columns have the same name. I want to make these two columns into one column and fill them with values. like this

column1
value1
value1
value1
value1
value2

What should I do?

Note that only one of the duplicate columns has a value.

1 Answer 1

2

Replace None string values by NaN float values, then stack which will convert the data to a single column dropping na values as dropna=True by default for stack, then finally unstack:

df.replace('None', float('nan')).stack().unstack()

OUTPUT:

   column1
0  value 1
1  value 1
2  value 1
3  value 1
4   value2
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.