I have an assignment that only allows matplotlib and basic python. I am unable to produce the bar chart required. Although anaconda has identified the problematic line, I am unable to understand it.
The data source is here: https://data.gov.sg/dataset/bookings-for-new-flats-annual?view_id=2cdedc08-ddf6-4e0b-b279-82fdc7e678ea&resource_id=666ed30a-8344-4213-9d2e-076eeafeddd3
Have copied a sample resource and replicated it.
import numpy as np
import matplotlib.pyplot as plt
fname = "C:\data/bookings-for-new-flats.csv"
data = np.genfromtxt('C:\data/bookings-for-new-flats.csv',
skip_header=1,
dtype=[('financial_year','U50'),('no_of_units','i8')], delimiter=",",
missing_values=['na','-'],filling_values=[0])
labels = list(set(data['financial_year']))
labels.sort()
bookings = np.arange(0,len(labels))
bookings_values = data[['financial_year','no_of_units']]
values = bookings_values['no_of_units']
units_values = {}
for i in labels:
valuesforFY = values[bookings_values['financial_year']==i]
print("No.of Units in FY: " + i + " is {}".format(valuesforFY))
#the line below is critical
units_values[i] = valuesforFY
barchart = plt.bar(list(units_values.keys()), list(units_values.values()), color='b')
plt.show()
Expected a bar-chart but only received a empty one.
The system identified this line as problematic --->
barchart = plt.bar(list(units_values.keys()), list(units_values.values()), color='b')