skip to Main Content

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 Intelligencecandlestick codec5.py”,
line 13, in df= pd.read_csv(‘nse2.csv’, parse_dates=True,
index_col=0) File “C:Program
FilesPython35libsite-packagespandasioparsers.py”, line 498, in
parser_f

return _read(filepath_or_buffer, kwds) File “C:Program
FilesPython35libsite-packagespandasioparsers.py”, line 275, in
_read
parser = TextFileReader(filepath_or_buffer, **kwds) File “C:Program FilesPython35libsite-packagespandasioparsers.py”,
line 590, in init
self._make_engine(self.engine) File “C:Program FilesPython35libsite-packagespandasioparsers.py”, line 731, in
_make_engine
self._engine = CParserWrapper(self.f, **self.options) File “C:Program FilesPython35libsite-packagespandasioparsers.py”,
line 1103, in init
self._reader = _parser.TextReader(src, **kwds) File “pandasparser.pyx”, line 353, in pandas.parser.TextReader.cinit
(pandasparser.c:3246) File “pandasparser.pyx”, line 591, in
pandas.parser.TextReader._setup_parser_source (pandasparser.c:6111)
OSError:

This is the main error

->” File b’nse2.csv’ does not exist”

2

Answers


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

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search