0% found this document useful (0 votes)
4 views8 pages

Data Science Assignment 3 H

The document presents a data science scenario involving the creation of a dataset to analyze sales data for a bakery over two consecutive weeks. It includes Python code to generate sales data for each week, as well as a method to divide the sales data into weekdays and weekends for separate analysis. The analysis provides total sales figures for both periods.

Uploaded by

lk0246
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views8 pages

Data Science Assignment 3 H

The document presents a data science scenario involving the creation of a dataset to analyze sales data for a bakery over two consecutive weeks. It includes Python code to generate sales data for each week, as well as a method to divide the sales data into weekdays and weekends for separate analysis. The analysis provides total sales figures for both periods.

Uploaded by

lk0246
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Data Science Scenario Questions

BY: SAI RAGHAVENDRA (RA2211003011012)


PRANEET RAO(RA2211003011054)
HARSH MEHROTRA (RA2211003011060)
7. Create a dataset showing sales for two
consecutive weeks by analyzing another
bakery branch’s sales, which mirrors your
data.
Solution:

import pandas as pd
# Sales data for the first week
data = {
"Day": ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
"Bread": [20, 25, 22, 30, 35, 40],
"Cakes": [15, 18, 16, 20, 25, 30],
"Cookies": [50, 55, 52, 60, 65, 70],
"Muffins": [10, 12, 11, 15, 20, 25],
"Pies": [5, 6, 7, 10, 15, 18]
}
# Creating DataFrame for Week 1
df_week1 = pd.DataFrame(data)
# Creating Week 2 data (Assumed same as Week 1)
df_week2 = df_week1.copy()
df_week2.columns = [col + " (Week 2)" if col != "Day" else col for col in
df_week2.columns]
# Merging both weeks' sales
df_combined = pd.concat([df_week1,
df_week2.drop(columns=["Day"])], axis=1)
print("Sales Data for Two Consecutive Weeks:\n")
print(df_combined.to_string(index=False))
8. Divide the weekly sales data into
two periods: weekdays and weekends,
and analyze each period separately.
Solutions:

import pandas as pd
# Sales data for the bakery
data = {
"Day": ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
"Bread": [20, 25, 22, 30, 35, 40],
"Cakes": [15, 18, 16, 20, 25, 30],
"Cookies": [50, 55, 52, 60, 65, 70],
"Muffins": [10, 12, 11, 15, 20, 25],
"Pies": [5, 6, 7, 10, 15, 18]
}
# Creating DataFrame
df = pd.DataFrame(data)
# Splitting data into weekdays and weekends
weekdays = df.iloc[:4] # Monday to Thursday
weekends = df.iloc[4:] # Friday and Saturday
# Calculate total sales for each period
weekday_totals = weekdays.iloc[:, 1:].sum()
weekend_totals = weekends.iloc[:, 1:].sum()
print("Total Sales for Weekdays (Monday-Thursday):\n", weekday_totals)
print("\nTotal Sales for Weekends (Friday-Saturday):\n", weekend_totals)

You might also like