[Solved]-Python Pulling Data Csv File Need Better Idea Also Pasted Link Repl Files Https Repl Nickl Q37275038
Python: Pulling data from CSV file.
If you need a better Idea I also pasted my link to repl for bothfiles.
https://repl.it/@nicklee11/InsidiousSteepCharactercode
I need the latitude, longitude, price and area of the housesalong with their addresses when I search for the zip code.
I also need to output average price per square foot of all thehouses in a zip code when I search zip code. Do this throughcreating a method of the house class that returns the price persquare foot of that house and then call the method appropriately inthe main() function.
Here is the code I have but I’m not able to figure out how toget this to work.
# This program uses objects to process housing data.
# Class to store data of a house
class house:
def __init__(self,street,city,zipcode,state) : # constructor
self.street = street
self.city = city
self.zipcode = int(zipcode)
self.state = state
def giveZipcode(self) :
return self.zipcode
def addArea(self,area) :
self.area = float(area)
def giveArea(self) :
return self.area
def addType(self,t) :
self.type = t
def giveType(self) :
return self.type
def giveLongitude(self) :
return self.Longitude
def Price(self) :
return self.Price
def writeAddress(self) :
print(“nAddress:”)
print(self.street)
print(self.city+”,”,self.state,self.zipcode)
print(self.Price)
print(self.Longitude)
print(self.Latitude)
def write(self) :
self.writeAddress()
# This function processes a line from the csv data file abouthousing
# and returns a house object.
def readHouseFromLine(line) :
cells = line.split(“,”)
h = house(cells[0],cells[1],cells[2],cells[3])
h.addArea(cells[6])
h.addType(cells[7])
return h
# This function reads data from the csv data file abouthousing
# and returns a list of house objects.
def readData(filename) :
house_list = []
infile = open(filename,”r”)
header_row = infile.readline() # skip the header row
for line in infile :
h = readHouseFromLine(line)
if h.giveArea() > 0 : # Area must be non-zero to include
house_list = house_list + [h]
return house_list
# This function reads data from data.csv file and
# then interactively lists the houses in a zipcode
# as queried by the user.
def main() :
houses = readData(“data.csv”)
moreSearch = “Yes”
while moreSearch==”Yes” :
z = int(input(“Give the zip code to list its houses: “))
count = 0
for h in houses :
if z==h.giveZipcode() :
count += 1
h.write()
if count==0 :
print(“No houses in this zipcode in the data.”)
moreSearch = input(“nDo you want to search for more zipcodes?Yes/No: “)
main()
Expert Answer
Answer to Python: Pulling data from CSV file. If you need a better Idea I also pasted my link to repl for both files. https://repl… . . .
OR

