for each item in each store, find the number of items in the same store within $2 price difference (i.e. number of items with similar price within the same store).
Then list all the items which has the greatest number of items.
The dataset has about 100,000 records so efficient is also important. My snapshot is a small subset for implementing ideas.
The first step has got me. I have tried groupby
, count
, sum
. None of these get me anywhere to get the desired output. I have used df.sort_values
on store_id
and price
. Can anyone give me a hint?
Below is some sample of my data.
import pandas as pd
data = {'item_id': ['6dd5392a9991','363a268ae1bc','fcd248a3fe97','20d197a04656','54c6463ffc87', '1b62f63eac43', '4ed99ff1bcdf', '6e19d5b8e99b','89c9b4655a9d', '16740613e6af'],
'store_id': ['1d632be3f72c','1d632be3f72c','1d632be3f72c','1d632be3f72c','b5d61bc3e6d1','b5d61bc3e6d1','b5d61bc3e6d1','b5d61bc3e6d1','b5d61bc3e6d1','b5d61bc3e61'],
'price': [23.54, 20.61, 13.63, 23.69, 13.79, 14.90, 4.09, 14.30, 4.47, 4.51]
}
df = pd.DataFrame(data)