Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Data Science by (17.6k points)

I have table x:




2   None

I want to replace python None with pandas NaN. I tried:

x.replace(to_replace=None, value=np.nan)

But I got:

TypeError: 'regex' must be a string or a compiled regular expression or a list or dict of strings or regular expressions, you passed a 'bool'

How should I go about it?

1 Answer

0 votes
by (41.4k points)
edited by

Use DataFrame.fillna or Series.fillna which will help in replacing the Python object None, not the string 'None'.

import pandas as pd

For dataframe:

df.fillna(, inplace=True)

For column or series:

df.mycol.fillna(, inplace=True)

If you want to know more about Machine Learning then watch this video:

If you wish to learn more about Data Science, visit Data science tutorial and Data science courses by Intellipaat.

Related questions

Browse Categories