私はテーブルを持っていますx
:
website
0 http://www.google.com/
1 http://www.yahoo.com
2 None
Python None を pandas NaN に置き換えたいです。試してみました:
x.replace(to_replace=None, value=np.nan)
しかし、私は次のものを得ました:
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'
どうすればいいでしょうか?
ベストアンサー1
使用できますDataFrame.fillna
またはSeries.fillna
None
文字列ではなく、Python オブジェクトを置き換えます'None'
。
import pandas as pd
import numpy as np
データフレームの場合:
df = df.fillna(value=np.nan)
列またはシリーズの場合:
df.mycol.fillna(value=np.nan, inplace=True)