0

I have a CSV that has two columns: ['item', 'price]. I want to calculate the total price of each item separately. For example, let's say that the 'item' column has 4 rows with the value 'brown shoes'. I want to find the sum of 'price' when df['item'] is equal to 'brown shoes'.

I have tried this:

for i in df['item']:
        if i == 'brown shoes':
           df = df.loc['price'].sum()

Not sure why this isn't working. The error i'm getting is:

"Unalignable boolean Series provided as " pandas.core.indexing.IndexingError: Unalignable boolean Series provided as indexer (index of the boolean Series and of the indexed object do not match).

Is there something i'm missing?

Jason000
  • 179
  • 2
  • 5
  • 14

0 Answers0