1

I have a csv loaded using pandas of sales data from a car dealership. One of the columns is titled "Status" and it contain either "Shipped", "In Process" or "Disputed".

I want to remove all of the rows that has "Disputed" or "In Process" from the dataframe.

Currently I have the following written:

for row in df: if df[:6] == 'Disputed': df.drop[row:6] print(df)

I'm sure the problem is the 'Disputed' part but I've tried a bunch of things and nothing worked.

1 Answers1

0

If there's three options, and you want to remove two options, then we could instead just choose the third option:

import pandas as pd

# Sample data
df = pd.DataFrame({
    'OrderID': [1, 2, 3, 4, 5],
    'CarModel': ['Sedan', 'SUV', 'Hatchback', 'Convertible', 'Pickup'],
    'Price': [25000, 35000, 20000, 45000, 30000],
    'Status': ['Shipped', 'In Process', 'Disputed', 'Shipped', 'In Process']
})
# select the ones with status "Shipped"
df[df['Status'] == 'Shipped']

   OrderID     CarModel  Price   Status
0        1        Sedan  25000  Shipped
3        4  Convertible  45000  Shipped
Mark
  • 7,785
  • 2
  • 14
  • 34