Search
 
SCRIPT & CODE EXAMPLE
 

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
Comment

PREVIOUS NEXT
Code Example
Python :: unittest run one test 
Python :: parse filename 
Python :: python string formatting - string truncating with format() 
Python :: range function without end value 
Python :: pydantic array of objects 
Python :: asterisk triangle print 
Python :: find factors of a number using while loop 
Python :: Convert Int to String Using F-strings 
Python :: Add OR Concatenation of Tuples in python 
Python :: python finding mead 
Python :: python log max age linux delete old logs 
Python :: copy string x times python 
Python :: python combine images horizontally next to each other 
Python :: 0xff in python 
Python :: python sumproduct excel 
Python :: counter and element of list for loop python 
Python :: comments 
Python :: Python NumPy moveaxis function Example 
Python :: with statement in python 
Python :: Python NumPy asfortranarray Function Tuple to an array 
Python :: python function arguments multiple lines 
Python :: python os.listdir attributes 
Python :: Python how to use __truediv__ 
Python :: selenium rotate user agent 
Python :: NumPy packbits Code Packed array along axis 1 
Python :: selenium python select elements data atribute 
Python :: green book résumé 
Python :: python dependency injection 
Python :: python Tkinter widget displacement with pack() 
Python :: dimensions of dataset in python 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =