Python Forum
Two Dimensional Chart from CSV File
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Two Dimensional Chart from CSV File
#1
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()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to add an element such as an average to a multi-dimensional array? xhughesey 6 4,008 Jan-06-2019, 10:47 PM
Last Post: xhughesey
  Three-dimensional Contour Plots minifizikus 1 3,275 Sep-13-2018, 10:56 PM
Last Post: Larz60+
  2 Dimensional NumPy for beginners Jack_Sparrow 2 3,107 May-08-2018, 05:21 PM
Last Post: killerrex
  Recurse through n-dimensional array ColdDeath 2 2,982 Apr-05-2018, 11:20 AM
Last Post: KenniT
  How to sum elements of same position in n dimensional array Felipe 2 4,131 May-11-2017, 10:33 AM
Last Post: Felipe

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020