Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

use dict to replace missing values pandas

d = {'apple': 1, 'peach': 6, 'watermelon': 4, 'grapes': 5, 'orange': 2,'banana': 3}

df["fruit_tag"] = df["fruit_tag"].map(d)
print (df)
   fruit_tag
0        1.0
1        2.0
2        3.0
3        4.0
4        NaN
5        NaN
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #dict #replace #missing #values #pandas
ADD COMMENT
Topic
Name
5+4 =