In [2]:
import numpy as np
from pandas import Series
In [3]:
ser1 = Series([1,2,3,4,1,2,3,4])
ser1
Out[3]:
0    1
1    2
2    3
3    4
4    1
5    2
6    3
7    4
dtype: int64
In [4]:
# replaceを使って、データを置換できます。
ser1.replace(1,np.nan)
Out[4]:
0   NaN
1     2
2     3
3     4
4   NaN
5     2
6     3
7     4
dtype: float64
In [5]:
ser1
Out[5]:
0    1
1    2
2    3
3    4
4    1
5    2
6    3
7    4
dtype: int64
In [6]:
# いくつかの置換を一度に指定することも可能です。
ser1.replace([1,4],[100,400])
Out[6]:
0    100
1      2
2      3
3    400
4    100
5      2
6      3
7    400
dtype: int64
In [7]:
# 辞書型で渡すことも可能です。
ser1.replace({4:np.nan})
Out[7]:
0     1
1     2
2     3
3   NaN
4     1
5     2
6     3
7   NaN
dtype: float64