Write a function bathing_soap_sales (fp, output_name) that takes the input fp as the name of a csv file containing sales
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Write a function bathing_soap_sales (fp, output_name) that takes the input fp as the name of a csv file containing sales
WEBSITE KEEP ON BEING WRONG.
I HAVE PROVIDED SCREENSHOTS OF THE QUESTION, EXAMPLE OF GRAPH,
TESTS YOU CAN RUN ON CODE, MY INCORRECT CODE THAT NEEDS
FIXING/REPLACING, AND THE ERRORS MY CODE PRODUCED.
Write a function bathing_soap_sales (fp, output_name) that takes the input fp as the name of a csv file containing sales data and output_name as the name of the produced plot.png. It then reads the contents as a Pandas dataframe, then plots a bar graph of bathing soap on the y-axis against month_number on the x-axis. You must use the Pandas dataframe plot method to create your bargraph. The graph itself must by formatted in this way: figure size is set to (10, 8) • x-axis tick labels are aligned vertically, not horizontally • legend is removed • a grid is applied over the plot area with a line width of 1 and a line style of '--' • x-axis label is 'Month' y-axis label is 'Sales Units' • plot title is 'Bathing Soap Sales Data' Finally, save the graph as output_name with a default value "output.png". The expected output when using plt.show() (for testing purposes) is seen below:
Sales Units 14000 12000 10000 8000 6000 4000 2000 0 1 2 3 4 Bathing Soap Sales Data 6 8 7 Month 5 9 10 11 12
import pandas as pd import matplotlib.pyplot as plt def bathing_soap_sales (fp, output_name = "output.png"): """""produces graph"!!!!** data=pd. read_csv (fp) df=pd.DataFrame (data) x_data= list(df.iloc[:, 0]) y_data = list(df.iloc[:, 1]) plt. figure(figsize=(10,8)) plt.xticks (rotation=90) plt.ylim( [0, 14000]) plt.xlabel('Month') plt.ylabel('Sales Unit') plt.title('Bathing Soap Sales Data') plt.bar(x_data, y_data) plt.bar(fp, output_name, label='Month') plt.grid (True, linewidth = "1", linestyle="--") plt.savefig (output_name)
Got Your graph is different to the expected output, difference: 0.1609 * Your graph is different to the expected output, difference: 0.1609 * Your graph is different to the expected output, difference: 0.1609 X
Test bathing_soap_sales('company_sales_data.csv') ans ('company_sales_data.csv') val = main("output.png", "answer.png") if val <= 0.05: print("Pass!") else: print("Your graph is different to the expected output, difference: { bathing_soap_sales('company_sales_data.csv') ans ('company_sales_data.csv') val = main("output.png", "answer.png") if val <= 0.1: print("Nearly!") else: print("Your graph is different to the expected output, difference: { bathing_soap_sales('company_sales_data.csv') ans ('company_sales_data.csv') val = main("output.png", "answer.png") if val <= 0.15: print("Partial") else: print("Your graph is different to the expected output, difference: