Created
January 11, 2020 09:00
-
-
Save hoyajigi/e0869c3723e3515880149398f898ff22 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import pandas as pd | |
with open('input_p2.json') as json_file: | |
df = pd.DataFrame(json.loads(line) for line in json_file) | |
groupByProductId = df.groupby('product_id') | |
countOfDistinctUserId = groupByProductId['user_id'].nunique().sort_values() | |
print("Most popular product(s) based on the number of purchasers: ", | |
countOfDistinctUserId.loc[countOfDistinctUserId == countOfDistinctUserId.max()].index.tolist()) | |
sumOfQuantity = groupByProductId.sum() | |
print("Most popular product(s) based on the quantity of goods sold: ", | |
sumOfQuantity.loc[sumOfQuantity['quantity'] == sumOfQuantity['quantity'].max()].index.tolist()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment