1

basically i have a dataframe where is a lot of columns, but the main are ITEM_ID and PRICE.

For example:

ID  ITEM_ID  ITEM     PRICE
1      1      potato    20
2      1      potato    20
3      1      potato    25
4      2      tomato    50
5      2      tomato    55
 

And I want to delete the rows where ITEM_ID and PRICE are equal, so the output will be this:

ID  ITEM_ID  ITEM     PRICE
1      1      potato    20
2      1      potato    25
3      2      tomato    50
4      2      tomato    55
 

I am counting average price using

df['AVG'] = df.groupby('ITEM_ID')['PRICE'].transform('mean')

But I realised, that I am counting using the duplicate values, so the average is not right.

Can anybody help?

EDIT:

After trying suggested

df.drop_duplicates(subset=['item_id', 'price'])

the data are still there, even keep=False wont do nothing.

Deesak
  • 153
  • 1
  • 16

1 Answers1

3

Solution to this problem is:

df.drop_duplicates(subset=['item_id', 'price'], inplace=True)
Deesak
  • 153
  • 1
  • 16