4 Replies - 415 Views - Last Post: 22 November 2019 - 09:32 PM Rate Topic: -----

#1 kam536   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 52
  • Joined: 21-March 18

How to get a csv file to be read

Posted 21 November 2019 - 06:52 PM

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import csv
import statistics

print("Hello,")
print("Welcome to the Python Data Analysis Application")

def menuOptions():
    print("\nSelect the file you want to analyze:\n")
    print("1.Population Data")
    print("2.Housing Data")
    print("3.Exit the Program")
    
    selection=int(input("\nWhat file do you want to analyze?: "))
    return selection
    
def readPopChange():
    popChange= pd.read_csv('/home/ec2-user/enviornment/Project5/PopChange.csv') 
    return popChange

readPopChange()

class POP:
    def __init__(self,line):
        self.data = line
        #Goes through each element and assign values
        self.id = self.data[0].strip()
        self.geography = self.data[1].strip()
        self.targetGeoId1 = self.data[2].strip()
        self.targetGeoId2 = self.data[3].strip()
        self.popApr1 = self.data[4].strip()
        self.popJul1 = self.data[5].strip()
        self.changePop = self.data[6].strip()
 
 
    
population=[]
popApr1=[]
with open('PopChange.csv','r') as p:
    reader=csv.reader(p)
    next(reader)
    for line in reader:
        population.append(POP(line))
        population.append(POP(line))
        
        obj = POP(line)
        popApr1.append(float(obj.popApr1))









    
def readHousing():
    housing=pd.read_csv('Housing.csv')
    print(housing)


def popMenu():
    print("Select the Column you want to analyze:\n")
    print('a.Pop Apr 1')
    print('b.Pop Jul 1')
    print('c.Change Pop')
    print('d.Exit Column')
    
    choice = (input('What do you want to do?: '))

while True:
    selection=menuOptions()
    if selection == 1:
        print('\nYou have entered Population Data.')
        readPopChange()
        






Im aware that my code is not finished. I just can't figure out how to get the csv file to be read.

Is This A Good Question/Topic? 0
  • +

Replies To: How to get a csv file to be read

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15431
  • View blog
  • Posts: 61,819
  • Joined: 12-June 08

Re: How to get a csv file to be read

Posted 21 November 2019 - 07:35 PM

What part are you having issue with?
Was This Post Helpful? 0
  • +
  • -

#3 kam536   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 52
  • Joined: 21-March 18

Re: How to get a csv file to be read

Posted 21 November 2019 - 08:29 PM

View Postmodi123_1, on 21 November 2019 - 07:35 PM, said:

What part are you having issue with?



This is what I'm getting when trying to run this:

Hello,
Welcome to the Python Data Analysis Application
Traceback (most recent call last):
File "/home/ec2-user/environment/Project5/Python Data Analysis Code.py", line 29, in <module>
readPopChange()
File "/home/ec2-user/environment/Project5/Python Data Analysis Code.py", line 26, in readPopChange
popChange= pd.read_csv('/home/ec2-user/enviornment/Project5/PopChange.csv')
File "/usr/local/lib64/python3.6/site-packages/pandas/io/parsers.py", line 685, in parser_f
return _read(filepath_or_buffer, kwds)
File "/usr/local/lib64/python3.6/site-packages/pandas/io/parsers.py", line 457, in _read
parser = TextFileReader(fp_or_buf, **kwds)
File "/usr/local/lib64/python3.6/site-packages/pandas/io/parsers.py", line 895, in __init__
self._make_engine(self.engine)
File "/usr/local/lib64/python3.6/site-packages/pandas/io/parsers.py", line 1135, in _make_engine
self._engine = CParserWrapper(self.f, **self.options)
File "/usr/local/lib64/python3.6/site-packages/pandas/io/parsers.py", line 1917, in __init__
self._reader = parsers.TextReader(src, **kwds)
File "pandas/_libs/parsers.pyx", line 382, in pandas._libs.parsers.TextReader.__cinit__
File "pandas/_libs/parsers.pyx", line 689, in pandas._libs.parsers.TextReader._setup_parser_source
FileNotFoundError: [Errno 2] File b'/home/ec2-user/enviornment/Project5/PopChange.csv' does not exist: b'/home/ec2-user/enviornment/Project5/PopChange.csv'
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6829
  • View blog
  • Posts: 28,314
  • Joined: 12-December 12

Re: How to get a csv file to be read

Posted 22 November 2019 - 02:37 AM

The first thing that jumps out from the error details is "FileNotFoundError". Does the file PopChange.csv exist at that location? Is it the correct location?

Is enviornment spelt correctly?
Was This Post Helpful? 0
  • +
  • -

#5 kam536   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 52
  • Joined: 21-March 18

Re: How to get a csv file to be read

Posted 22 November 2019 - 09:32 PM

View Postandrewsw, on 22 November 2019 - 02:37 AM, said:

The first thing that jumps out from the error details is "FileNotFoundError". Does the file PopChange.csv exist at that location? Is it the correct location?

Is enviornment spelt correctly?


I finally figured out what was going on! Thank you!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1