Reputation: 826
I am trying to drop the rows in my pandas dataframe that have no price in them. Technically, in the data source the dollar sign ($) appears by default so
df1.dropna(subset=['Price ($)'], inplace = True)
does not work in my case. How can I drop the rows that have no price attached to them.
import pandas as pd
first = pd.read_excel('......')
df1 = pd.DataFrame(first)
Car Price ($)
Honda $200
Benz $ ----------> drop
Chevy $300
BMW $250
Kia $ ----------> drop
Upvotes: 0
Views: 139
Reputation: 38415
The other answer would work perfectly fine but here is another approach
df = df[df['Price ($)'].str.contains('\d+')]
This would ensure that you get only the rows where there is a numeric price available in the Price column. As a bonus, this is also faster:)
Upvotes: 1
Reputation:
If I understand correctly this should work:
first = first[first['Price ($)'] != '$']
This just keeps rows where the Price column isn't equal to '$'
Upvotes: 3