2

I wrote the following script that runs perfectly when using pyCharm, but when I go to run it in a terminal it gives me these errors:

  File "/Users/Chris/PycharmProjects/firstfile/trial.py", line 6, in <module>
    r = pf.read_csv('python.csv')
  File "/usr/local/lib/python2.7/site-packages/pandas/io/parsers.py", line 562, in parser_f
    return _read(filepath_or_buffer, kwds)
  File "/usr/local/lib/python2.7/site-packages/pandas/io/parsers.py", line 315, in _read
    parser = TextFileReader(filepath_or_buffer, **kwds)
  File "/usr/local/lib/python2.7/site-packages/pandas/io/parsers.py", line 645, in __init__
    self._make_engine(self.engine)
  File "/usr/local/lib/python2.7/site-packages/pandas/io/parsers.py", line 799, in _make_engine
    self._engine = CParserWrapper(self.f, **self.options)
  File "/usr/local/lib/python2.7/site-packages/pandas/io/parsers.py", line 1213, in __init__
    self._reader = _parser.TextReader(src, **kwds)
  File "pandas/parser.pyx", line 358, in pandas.parser.TextReader.__cinit__ (pandas/parser.c:3427)
  File "pandas/parser.pyx", line 628, in pandas.parser.TextReader._setup_parser_source (pandas/parser.c:6861)
IOError: File python.csv does not exist

Could someone point in the the right direction? I am guessing that it has to do with the csv file not being in the right path or directory. Right now I have the csv file saved in the same folder as my .py project. I also checked and made sure I have the right packages installed, so I do not think it is that.

import csv
import pandas as pf

r = pf.read_csv('python.csv')
r.head()

print r.describe()
tradeDates = r['Trade Date'].unique()

r.name = 'Trade Date'
for trades in tradeDates:
outfilename = trades
printName = outfilename + ".csv"
print printName
r[r['Trade Date'] == trades].to_csv(printName, index=False)
8
  • .csv file path: /Users/Chris/PycharmProjects/firstfile/python.csv ||||| .py file path: /Users/Chris/PycharmProjects/firstfile/trial.py Commented May 15, 2016 at 5:19
  • How do you run the code in therminal? Commented May 15, 2016 at 5:19
  • python /Users/Chris/PycharmProjects/firstfile/trial.py Commented May 15, 2016 at 5:20
  • Try putting the full file path in your program Commented May 15, 2016 at 5:21
  • Try changing your directory to /Users/Chris/PycharmProjects/firstfile and running python trial.py Commented May 15, 2016 at 5:22

1 Answer 1

1

When you run python /Users/Chris/PycharmProjects/firstfile/trial.py python looks for csv file in your current directory, not in /Users/Chris/PycharmProjects/firstfile. You either need to change your directory before running the code, or you need to use the full path in trial.py like this:

import csv
import pandas as pf

r = pf.read_csv('/Users/Chris/PycharmProjects/firstfile/python.csv')
r.head()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.