I am trying to drop rows in pandas based on whether or not it contains "/" in the cells in column "Price". I have referred to the question: Drop rows in pandas if they contains "???".
As such, I have tried both codes:
df = df[~df["Price"].str.contains('/')]
and
df = df[~df["Price"].str.contains('/',regex=False)]
However, both codes give the error: AttributeError: Can only use .str accessor with string values!
For reference, the first few rows of my dataframe is as follows:
Fruit Price 0 Apple 3 1 Apple 2/3 2 Banana 2 3 Orange 6/7 May I know what went wrong and how can I fix this problem? Thank you very much!
dtypeand see what's its dtype and try casting to string if its not a string usingastypeobjectis ok. I think this column have NaN values