The file contains some data points in Melbourne housing data.
1. Average price per Suburb (Suburd name in X-axis and Average price in Y-Axis)
2. Total price per Built year (Built year in X-axis and Total price of all houses built that year in Y-axis)
For the 1st question i wrote a program but it shows an error.
import csv
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
file = open('FileData.csv', "rb") #Open CSV File in Read Mode
reader = csv.reader(file) #Create reader object which iterates over lines
class Object: #Object to store unique data
def __init__(self, name, price, count):
self.name = Suburb
self.Price = price
self.count = amount
class Object_p: #Object to store unique data
def __init__(self, name, avgprice):
self.name = Suburb
self.avgPrice = avgprice
rownum = 0 #Row Number currently iterating over
list = #List to store objects
def checkList(name, price, count):
for object in list: #Iterate through list
if object.name == name :
and object.price += price
object.count += 1
return
newObject = Object(name, price, int(1)) #Create a new object with new name
list.append(newObject) #Add to list and break out
for row in reader: #Iterate through all the rows
if rownum == 0: #Store header row seperately to not get confused
header = row
else:
name = row[0] #Suburb
price = row[1] #Price
Count = row[2] #Count
if len(list) == 0: #Default case if list = 0
newObject = Object(name, price, int(1))
list.append(newObject)
else: #If not...
checkList(name, price, 1)
rownum += 1
for each in list: #Print out result
print each.name, each.price, each.count
Object_p.name == each.name
Object_p.avg_price == each.price/each.count
file.close() #Close file
data = Object_p
data.plot(kind='bar')
plt.ylabel('Price')
plt.xlabel('Suburbs')
plt.title('Avg. Price by Suburb')
plt.show()
1. Average price per Suburb (Suburd name in X-axis and Average price in Y-Axis)
2. Total price per Built year (Built year in X-axis and Total price of all houses built that year in Y-axis)
For the 1st question i wrote a program but it shows an error.
import csv
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
file = open('FileData.csv', "rb") #Open CSV File in Read Mode
reader = csv.reader(file) #Create reader object which iterates over lines
class Object: #Object to store unique data
def __init__(self, name, price, count):
self.name = Suburb
self.Price = price
self.count = amount
class Object_p: #Object to store unique data
def __init__(self, name, avgprice):
self.name = Suburb
self.avgPrice = avgprice
rownum = 0 #Row Number currently iterating over
list = #List to store objects
def checkList(name, price, count):
for object in list: #Iterate through list
if object.name == name :
and object.price += price
object.count += 1
return
newObject = Object(name, price, int(1)) #Create a new object with new name
list.append(newObject) #Add to list and break out
for row in reader: #Iterate through all the rows
if rownum == 0: #Store header row seperately to not get confused
header = row
else:
name = row[0] #Suburb
price = row[1] #Price
Count = row[2] #Count
if len(list) == 0: #Default case if list = 0
newObject = Object(name, price, int(1))
list.append(newObject)
else: #If not...
checkList(name, price, 1)
rownum += 1
for each in list: #Print out result
print each.name, each.price, each.count
Object_p.name == each.name
Object_p.avg_price == each.price/each.count
file.close() #Close file
data = Object_p
data.plot(kind='bar')
plt.ylabel('Price')
plt.xlabel('Suburbs')
plt.title('Avg. Price by Suburb')
plt.show()