-2

I was executing this code when i encountered this error related to file not found. File exists in the same folder where code resides, bu still this error is not going. Please help!

code:

import datetime as dt
import matplotlib.pyplot as plt
from matplotlib import style
from matplotlib.finance import candlestick_ohlc
import matplotlib.dates as mdates
import pandas as pd
import pandas_datareader.data as web
import numpy as np

style.use('ggplot')
df= pd.read_csv('nse2.csv', parse_dates=True, index_col=0)
df_ohlc= df['close'].resample('10D').ohlc()
df_ohlc.reset_index(inplace=True)
print(df_ohlc.head())
ax1 = plt.subplot2grid((6,1),(0,0), rowspan=5, colspan=1)
ax2 = plt.subplot2grid((6,1),(5,0), rowspan=1, colspan=1, sharex=ax1)
ax1.xaxis_date()
candlestick_ohlc(ax1,df_ohlc.values, width=2, colorup='g')
plt.show()

Here is the Error:

Traceback (most recent call last):

File "F:\Report on Artificial Intelligence\candlestick code\c5.py", line 13, in df= pd.read_csv('nse2.csv', parse_dates=True, index_col=0) File "C:\Program Files\Python35\lib\site-packages\pandas\io\parsers.py", line 498, in parser_f

return _read(filepath_or_buffer, kwds) File "C:\Program Files\Python35\lib\site-packages\pandas\io\parsers.py", line 275, in _read parser = TextFileReader(filepath_or_buffer, **kwds) File "C:\Program Files\Python35\lib\site-packages\pandas\io\parsers.py", line 590, in init self._make_engine(self.engine) File "C:\Program Files\Python35\lib\site-packages\pandas\io\parsers.py", line 731, in _make_engine self._engine = CParserWrapper(self.f, **self.options) File "C:\Program Files\Python35\lib\site-packages\pandas\io\parsers.py", line 1103, in init self._reader = _parser.TextReader(src, **kwds) File "pandas\parser.pyx", line 353, in pandas.parser.TextReader.cinit (pandas\parser.c:3246) File "pandas\parser.pyx", line 591, in pandas.parser.TextReader._setup_parser_source (pandas\parser.c:6111) OSError:

This is the main error

->" File b'nse2.csv' does not exist"

cs95
  • 379,657
  • 97
  • 704
  • 746
  • I'm still unsure at what i'm looking at, but this link might help you: https://stackoverflow.com/questions/10840533/most-pythonic-way-to-delete-a-file-which-may-not-exist – Sasha Jul 13 '17 at 14:27
  • 1
    python doesn't look for files relative to the folder where the code is, it looks for files relative to your current working directory. – Bryan Oakley Jul 13 '17 at 14:27

2 Answers2

0

My first guess is that you executed the script from in a different location other than the directory the 'bse2.scv' file is located.

rabbit
  • 21
  • 4
0

You need to either use the full path, or change the working directory.

import os
os.chdir("/Users/foo/bar")

You can see your current working directory by doing:

os.getcwd()

Personally I find that using the full path is always good practice.

Batman
  • 8,571
  • 7
  • 41
  • 80