Question: 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)
Q:6Objective: 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 help of question 4 ans given above
 Q:4(Answer) import pandas as pd def compute_profit_per_dollar_sold(df): # Calculate profit per

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!