0

I have the following table (df):

Col1 Col2 Col3
A1 finished 1234
A2 ongoing 1235
A3 NaN 1236
A4 finished 1237
A5 started 1238
A6 NaN 1239

I would like to replace the NaNs in the dataframe with empty_row. How do I do that?

Desired output:

Col1 Col2 Col3
A1 finished 1234
A2 ongoing 1235
A3 empty_row 1236
A4 finished 1237
A5 started 1238
A6 empty_row 1239

What I tried so far?

if df['col2'] == 'NaN': df['col2'] = 'empty_row' 

I get the following error: ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

How do I solve this?

0

1 Answer 1

2

You should use the fillna method https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.fillna.html

df['col2'] = df['col2'].fillna('empty_row') 
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.