i need to find 5 dates in which the greatest number of orders were placed from excel file

Viewed 54

here is the example of the question

 import pandas as pd
 # read excel file
 df = pd.read_excel("C:/Users/samer/Desktop/project/online_retail2.xlsx")
 df.head()
 # is gonna remove nan from the equation
 df = df.dropna()

 columns = list(df.columns)
 columns = [x.lower() for x in columns]
 df.columns = columns
 #task 2.1
 df['stockcode'] = df['stockcode'].apply(str)

 df["products ordered by individuals"] = df["description"] + [' '] + df["stockcode"]

 top_products = df['products ordered by individuals'].value_counts()[:10]
 print('Top 10 products ordered by individuals:\n' , top_products)

 #task 2.2
 df['sales'] = df['price'] * df['quantity']
 The_most_money_spent= df.groupby("customer id").sum().sort_values("sales", ascending=False).head(10)
 print("Top ten customers who spent most money are: \n" ,The_most_money_spent)


#task 2.3
top_orders_were_placed = df[['invoicedate','sales']].value_counts('sales','invoicedate', 
ascending=False)
top_orders_were_placed.head(5)


df['orders']= df[['sales', 'invoicedate']]
top_orders_were_placed= df['orders'].value_counts(ascending=False)
top_orders_were_placed.head()

I'm trying to find a way to get the greatest number of products, but I just don't know how to use or find the date from the file. despite numerous attempts, I just can't figure it out, and it's been 2 days, so what exactly should I use?

1 Answers

You need to use groupby function of pandas. You need to groupby by date and then summarize the quantity. After that you just need to sort values by descending.

Related