Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q: 4 ( Answer ) import pandas as pd def compute _ profit _ per _ dollar _ sold ( df ) : # Calculate

Q:4(Answer)
import pandas as pd
def compute_profit_per_dollar_sold(df):
# Calculate profit per dollar sold
df['profit_per_dollar_sold']= df['Profit']/ df['Sales']
# Return the dataframe with the new column
return df
# Example of usage:
# Assuming df is your pandas dataframe with columns "Profit" and "Sales"
new_df = compute_profit_per_dollar_sold(df)
Q6:
Objective: Filter data over relevant columns To understand how profit has evolved over time, create a function compute_time_average. This function receives as input a pandas dataframe and list of integers representing years, e.g.,[2014,2015], and computes the mean profit_per_dollar_sold for each year in the list. Repeat the same process to compute the mean Discount for each year. Return the result as tuple with two lists: - the first with the mean profit_per_dollar_sold per year, - the second with the mean Discount per year Round the values to two decimal places. Note: the lists must be aligned so that mean_profit_per_dollar_sold[1] and mean_discount[1] have the average for the year in list_years[1]. Hint: There are different ways to compute this. A possible one requires you to filter the data in the dataframe for each year. You can use other methods also covered in Programming Inception. Example of usage: mean_profit_per_dollar_sold, mean_values_discount = compute_time_average(new_df,[2014,2015,2016,2017,2018]),- new_df the pandas dataframe from question 4; - mean_profit_per_dollar_sold is a list with floats with the average profit_per_dollar_sold for each year; - mean_discount is a list with floats with the average discount for each year in the list_years;
Answer question 6 with the help of questions 4 Answer given above.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

OpenStack Trove

Authors: Amrith Kumar, Douglas Shelley

1st Edition

1484212215, 9781484212219

More Books

Students also viewed these Databases questions

Question

Design an internal skills transfer system through tutoring.

Answered: 1 week ago