Question: In [ ]: In [ ]: In [ ]: In [ ]: ord_no purch_amt ord_date customer_id salesman_id 0 70001 150.50 2012-10-05 3005 5002 1
In [ ]: In [ ]: In [ ]: In [ ]: ord_no purch_amt ord_date customer_id salesman_id 0 70001 150.50 2012-10-05 3005 5002 1 70009 270.65 2012-09-10 3001 5005 2 70002 65.26 2012-10-05 3002 5001 3 70004 110.50 2012-08-17 3009 5003 4 70007 948.50 2012-09-10 3005 5002 5 70005 2400.60 2012-07-27 3007 5001 6 70008 5760.00 2012-09-10 3002 5001 7 70010 1983.43 2012-10-10 3004 5006 8 70003 2480.40 2012-10-10 3009 5003 9 70012 250.45 2012-06-27 3008 5002 10 70011 75.29 2012-08-17 3003 5007 11 70013 3045.60 2012-04-25 3002 5001 Q6. Create a Pandas dataframe to store above dataset. The ord_date should be used as row index and stored as timeseries (not stored as character string!) Q7. Write a Pandas program to calculate the monthly total purchase amount (purch_amt). You only need to consider the months that exist in above dataset. Q8. Use pivot function the re-organize the dataset such that each row represent a salesman, each column represent a customer, and each element in the table represents the purchase amount. Q9. For each row, let variable "previous_month_sales" be the total purch_amt of the corresponding salesman in previous month. For example, for the first row, salesman_id=5002 and order date is in Oct. Then you need to find the total sales of salesman_id=5002 in Sep. If there is no data, set previous_month_sales as 0. Write a Pandas program to calculate the value of variable previous_month_sales for each row.
Step by Step Solution
3.45 Rating (155 Votes )
There are 3 Steps involved in it
To achieve the tasks described in Q6Q9 you can use the following Python code with Pandas import pand... View full answer
Get step-by-step solutions from verified subject matter experts
