import numpy as np
import pandas as pd
from pandas import Series, DataFrame
# Lets make Series
ser1 = Series([1,2,3,4,1,2,3,4])
#Show
ser1
0 1 1 2 2 3 3 4 4 1 5 2 6 3 7 4 dtype: int64
# Using replace we can select --> .replace(value to be replaced, new_value)
ser1.replace(1,np.nan)
0 NaN 1 2 2 3 3 4 4 NaN 5 2 6 3 7 4 dtype: float64
#Can also input lists
ser1.replace([1,4],[100,400])
0 100 1 2 2 3 3 400 4 100 5 2 6 3 7 400 dtype: int64
#Can also input dictionary
ser1.replace({4:np.nan})
0 1 1 2 2 3 3 NaN 4 1 5 2 6 3 7 NaN dtype: float64
#That's it for replace, next up Renaming an axis index