Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

replace all occurrences of a value to nan in pandas

import pandas as pd
import numpy as np

df = pd.DataFrame({'col1':['one', 'two', 'three', 'four']})

df['col1'] = df['col1'].map(lambda x: np.nan if x in ['two', 'four'] else x)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #replace #occurrences #nan #pandas
ADD COMMENT
Topic
Name
2+3 =