4.10. Series Modification

values = [1, 3, 5, np.nan, 6, 8]
s = pd.Series(values)
# 0    1.0
# 1    3.0
# 2    5.0
# 3    NaN
# 4    6.0
# 5    8.0
# dtype: float64

4.10.1. Fill NaN values

  • can use with inplace=True

s.fillna(0.0)
# 0    1.0
# 1    3.0
# 2    5.0
# 3    0.0
# 4    6.0
# 5    8.0
# dtype: float64

4.10.2. Drop rows with NaN values

s.dropna(inplace=True)
# 0    1.0
# 1    3.0
# 2    5.0
# 4    6.0
# 5    8.0
# dtype: float64

4.10.3. Reset index

  • drop=True to avoid the old index being added as a column

s.reset_index(drop=True)
# 0    1.0
# 1    3.0
# 2    5.0
# 3    6.0
# 4    8.0
# dtype: float64

4.10.3.1. Assignments

Todo

Create assignments