0

I tried with drop() but it deletes both the rows. I even tried to transpose the dataframe and then delete the column, but it deletes both the columns. Note that I do not want to use row number to exclude the row. I want to delete one of the rows using the value in some other column. Thank you in advance!!

purchase_1 = pd.Series({'Name': 'Chris',
                        'Item Purchased': 'Dog Food',
                        'Cost': 22.50})
purchase_2 = pd.Series({'Name': 'Kevyn',
                        'Item Purchased': 'Kitty Litter',
                        'Cost': 2.50})
purchase_3 = pd.Series({'Name': 'Vinod',
                        'Item Purchased': 'Bird Seed',
                        'Cost': 5.00})
purchase_4 = pd.Series({'Name': 'Vinod',
                        'Item Purchased': 'Dog Food',
                        'Cost': 5.00})
df1 = pd.DataFrame([purchase_1, purchase_2, purchase_3, purchase_4], index=['Store 1', 'Store 1', 'Store 2', 'Store 2'])

''' 
df::

         Name   Item Purchased  Cost
Store 1  Chris   Dog Food      22.5
Store 1  Kevyn   Kitty Litter   2.5
Store 2  Vinod   Bird Seed      5.0
Store 2  Vinod   Dog Food       5.0
'''

Expected output::

     One of the 'Store 1' rows deleted using values from some other column value like 'Dog Food' or 'Kitty Litter' or 22.5 or 2.5

1 Answers1

1

This returns you all rows that don't contain "Dog Food" in their "Item Purchased" column:

new_df = df[df["Item Purchased"] != "Dog Food"]
mrzo
  • 2,002
  • 1
  • 14
  • 26
  • I do not want to exclude the row that contains 'Dog Food'. I want to know how to delete 1 of the two rows who have same name based on a column value – Segmentation fault Jul 06 '20 at 12:03