-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4.2.1
More file actions
20 lines (17 loc) · 661 Bytes
/
4.2.1
File metadata and controls
20 lines (17 loc) · 661 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import pandas as pd
# Prompt the user for the file name
file_name = input()
# Load the data
df = pd.read_csv(file_name)
df['Date'] = pd.to_datetime(df['Date'])
#Extract the month from the Date column
df ['Month'] = df['Date'].dt.to_period('M')
#Calculate the total sales for each row
df['Total_Sales'] = df['Quantity'] * df['Price']
#Group the data by Month and calculate the total sales for each month
monthly_sales = df.groupby('Month') ['Total_Sales'].sum()
# Find the month with the highest total sales
best_month = monthly_sales.idxmax()
highest_sales = monthly_sales.max()
print(f"Best month: {best_month}")
print(f"Total sales: ${highest_sales:.2f}")