Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Q: 4 ( Answer ) import pandas as pd def compute _ profit _ per _ dollar _ sold ( df ) : # Calculate
Q:Answer
import pandas as pd
def computeprofitperdollarsolddf:
# Calculate profit per dollar sold
dfprofitperdollarsold' dfProfit dfSales
# Return the dataframe with the new column
return df
# Example of usage:
# Assuming df is your pandas dataframe with columns "Profit" and "Sales"
newdf computeprofitperdollarsolddf
Q:
Objective: Filter data over relevant columns To understand how profit has evolved over time, create a function computetimeaverage. This function receives as input a pandas dataframe and list of integers representing years, eg and computes the mean profitperdollarsold 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 profitperdollarsold 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 meanprofitperdollarsold and meandiscount have the average for the year in listyears 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: meanprofitperdollarsold, meanvaluesdiscount computetimeaveragenewdf newdf the pandas dataframe from question ; meanprofitperdollarsold is a list with floats with the average profitperdollarsold for each year; meandiscount is a list with floats with the average discount for each year in the listyears;
Answer question with the help of questions Answer given above.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started