Avatar ·

Replacing values in a particular Dataframe column by dictionary

📁 Advanced Python Topics

It is necessary to replace the values in a particular Dataframe column by the dictionary, if not found, you need to remove the entire row from Dataframe.

I was able to complete the task as:

dict1 = {'car': 'c', 'motorcycle': 'mt', 'truck': 'tr'} df = pd.DataFrame({'product': 'Truck Motorcycle Car Tire Wheel Truck'.split(), 'price': [10000, 5000, 23000, 15000, 50]})