Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

This the link for the steps to do it. https://docs.google.com/document/d/1O8B0MHZMKz04XFudUQA1c7dAAnkh2fj7/edit ?usp=sharing&ouid=1 XXXXXXXXXX&rtpof=true&sd=true This is the link for the csv file:...

1 answer below »



This the link for the steps to do it.
https:
docs.google.com/document/d/1O8B0MHZMKz04XFudUQA1c7dAAnkh2fj7/edit
?usp=sharing&ouid=1 XXXXXXXXXX&rtpof=true&sd=true

This is the link for the csv file:
https:
drive.google.com/file/d/1WLz3nDx-
O8FD2UBNmP0ZIGaM3tjlvgKN/view?usp=sharing

The first file contains the output that is required with the steps to do it and below is the code
which i did to plot a graph using matplotlib.
If possible can anyone continue with the changes in below code, otherwise you can do it
your way.
I am not able to get the output, please anyone help.

import csv
from datetime import datetime
import matplotlib.pyplot as plt
import matplotlib.ticker as mtick
data = []
csv_file = open('produce_extra.csv', 'r')
eader = csv.reader(csv_file)
for row in reader: # ! main loop reads one row at a time
if reader.line_num == 1: # ! get the location names from row 1
locations = row[2:] # ! slice to remove commodity and date
else:
for location, value in zip(locations, row[2:]): # ! iterate through locations and
values
XXXXXXXXXXrow_num = len(data) # ! index for the data row
XXXXXXXXXXdata.append(row[:2]) # ! new data row: commodity and date
XXXXXXXXXXdata[row_num].append(location) # ! append location
XXXXXXXXXXdate = datetime.strptime(data[row_num][1],'%m/%d/%Y')
XXXXXXXXXXdata[row_num][1]= date;
XXXXXXXXXXdata[row_num].append(float(value.replace('$', ''))) # ! append value
csv_file.close()
#creating lists of commodities,dates,locations
commodities = list(set([x[0] for x in data]))
dates = list(set([x[1] for x in data]))
locations = list(set([x[2] for x in data]))
# Filter object is not iterable and cannot be used as list comprehension
# Hence convert to list before getting values
select = list(filter(lambda x: x[0]=='Cauliflower' and x[2]=='New York',data))
date = [x[1] for x in select]
price = [x[3] for x in select]
# Change figure size to prevent overlapping
fig,ax = plt.subplots(figsize=(20,10))
ax.plot(date,price,label="Cauliflower in New York")
ax.set_xlabel('Date')
ax.set_ylabel('Price in Dollors')
# formatting the y axis to show dollors and cents
fmt = '${x:,.2f}'
# rename attributes to right one
tick = mtick.StrMethodFormatter(fmt)
ax.yaxis.set_major_formatter(tick)
plt.legend()
plt.show()
#creating an output file to see new data in spreadsheet.
esultfile = open('result.csv','w')
writer = csv.writer(resultfile,lineterminator='\n')
writer.writerows(data)
esultfile.close()
And use these codes
Answered 2 days After Nov 29, 2021

Solution

Sandeep Kumar answered on Dec 02 2021
125 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here