I have a list of cars and their prices. I need to apply log transformation on the prices, but some prices are set to 0, so I first need to create a copy of my original df with the prices filtered out:
import pandas as pd
import numpy as np
cars = {'Brand': ['Honda Civic','Toyota Corolla','Ford Focus','Audi A4'],
'Price': [22000,25000,27000,35000]
}
df = pd.DataFrame(cars, columns = ['Brand', 'Price'])
print (df)
df2 = df.loc[(df.Price>=22000) & (df.Brand=='Honda Civic')]
print(df2)
df2['logprice']=np.log(df2['Price'])
I get the warning
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
But I'm already using .loc !
I've read everything about this warning but I still don't understand what I'm doing wrong...