Divyanshi 05401172023 Ds Practical
Divyanshi 05401172023 Ds Practical
Visualizations
# Find the month with the highest Cost of Goods Sold (COGS)
highest_cogs_month = data.groupby(data['Date'].dt.month)
['cogs'].sum().idxmax()
print("Month with the highest Cost of Goods Sold (COGS):",
highest_cogs_month)
datetime64[ns]
Total revenue by month:
Date
1 116291.868
2 97219.374
3 109455.507
Name: Total, dtype: float64
Month with the highest Cost of Goods Sold (COGS): 1
average_quantity_sold = data['Quantity'].mean()
Time of the day when customers give the most ratings: 19:48:00
26. Which time of the day do customers give
most ratings per branch?
most_rated_time_of_day_per_branch = data.groupby(['Branch', 'Time'])
['Rating'].sum().idxmax()
print("Time of the day when customers give the most ratings per
branch:", most_rated_time_of_day_per_branch)
Time of the day when customers give the most ratings per branch: ('C',
'10:23:00')
Day of the week with the best average ratings per branch: ('B', 0)
# Extract month, day of the week, and hour from the date
data['Month'] = data['Date'].dt.month
data['DayOfWeek'] = data['Date'].dt.dayofweek
data['Hour'] = data['Time'].apply(lambda x: int(x.split(':')[0]))
# Plotting
plt.figure(figsize=(18, 5))
plt.subplot(1, 3, 1)
plt.plot(total_sales_by_month, marker='o')
plt.title('Total Sales by Month')
plt.xlabel('Month')
plt.ylabel('Total Sales')
plt.subplot(1, 3, 2)
plt.plot(total_sales_by_day_of_week, marker='o')
plt.title('Total Sales by Day of the Week')
plt.xlabel('Day of the Week')
plt.ylabel('Total Sales')
plt.subplot(1, 3, 3)
plt.plot(total_sales_by_hour, marker='o')
plt.title('Total Sales by Hour of the Day')
plt.xlabel('Hour of the Day')
plt.ylabel('Total Sales')
plt.tight_layout()
plt.show()
30. Are there any differences in customer
ratings between branches?
ratings_by_branch = data.groupby('Branch')['Rating'].mean()
print("Average ratings by branch:")
print(ratings_by_branch)