0
$\begingroup$

I have a column in my dataframe which has 'True' as a value and all other values are NaNs (so there are no 'false' values). I want to plot a countplot for the said data in seaborn but want to include the NaNs as well. Basically, I want to convert the NaNs to 'false' values and plot a graph then but I dont want to make any changes to my original column. Is there a way I can create a separate category for NaNs as False category and plot it alongside the True category?

$\endgroup$
1
  • $\begingroup$ You would like to replace nan values with False value as boolean in one column, but this update will be on a new dataframe, not the original one, is that your question? $\endgroup$
    – user119783
    Jun 25, 2021 at 13:16

1 Answer 1

0
$\begingroup$

Yes, you can make a copy of your dataframe to a new dataframe and then apply the conversion from NaN to false as follows:

df2 = df.copy()

df2['column'] = df2['column'].fillna(False)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.