Replacing values in a particular Dataframe column by dictionary
📁 python
It is necessary to replace the values in a particular Dataframe column by the dictionary, if you are not found, you need to remove the entire line from Dataframe.
I was able to complete the task as:
DICT1 = { 'car' : 'c' , '' motorcycle" : 'mt' , 'truck' : ''}} df = pd.dataframe ({span class> '' 'product ": 'Truck Motorcycle Car Tire Wheel Truck' . Split (), 'price' : 10000 , 5000 , 23000 , 15000 , 500 , 300 , 8000 ]}) df [ 'product_new' ] = df [ '' 'product' ]. map (dict1) df.dropna (inplace = true ) df.drop ( '' 'product' , axis = 1 , inplace = true ) df_new = df.reindex (columns = [ '' 'product_new' , 'price' ]) is it possible to replace values immediately in the product column without creating an intermediate column and getting rid of the lines by which the key in the dictionary was not found?
replace
, but somehow it did not work out.