THE ERROR I AM GETTING IS :-
Traceback (most recent call last):
File "C:\Users\MAVERICK\Desktop\FINANCE PYTHON\candlestickgraph.py", line 16, in <module>
ohlc = data.loc[:, ['Date', 'Open', 'High', 'Low', 'Close']]
File "C:\Users\MAVERICK\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\core\indexing.py", line 1762, in __getitem__
return self._getitem_tuple(key)
File "C:\Users\MAVERICK\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\core\indexing.py", line 1289, in _getitem_tuple
retval = getattr(retval, self.name)._getitem_axis(key, axis=i)
File "C:\Users\MAVERICK\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\core\indexing.py", line 1954, in _getitem_axis
return self._getitem_iterable(key, axis=axis)
File "C:\Users\MAVERICK\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\core\indexing.py", line 1595, in _getitem_iterable
keyarr, indexer = self._get_listlike_indexer(key, axis, raise_missing=False)
File "C:\Users\MAVERICK\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\core\indexing.py", line 1552, in _get_listlike_indexer
self._validate_read_indexer(
File "C:\Users\MAVERICK\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\core\indexing.py", line 1654, in _validate_read_indexer
raise KeyError(
KeyError: 'Passing list-likes to .loc or [] with any missing labels is no longer supported, see https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#deprecate-loc-reindex-listlike'
i was trying to get data directly to plot ohlc but its giving this error please help.
i have given the code which i tried:-
What I have tried:
# python_candlestick_chart.py
import datetime as dt
import matplotlib.pyplot as plt
from mpl_finance import candlestick_ohlc
import pandas as pd
import matplotlib.dates as mpl_dates
import pandas_datareader.data as web
plt.style.use('ggplot')
start = dt.datetime(1980,1,1)
end = dt.datetime(2020,5,22)
# Extracting Data for plotting
data = web.DataReader('INFY.NS' , 'yahoo' , start , end)
ohlc = data.loc[:, ['Date', 'Open', 'High', 'Low', 'Close']]
ohlc['Date'] = pd.to_datetime(ohlc['Date'])
ohlc['Date'] = ohlc['Date'].apply(mpl_dates.date2num)
ohlc = ohlc.astype(float)
# Creating Subplots
fig, ax = plt.subplots()
candlestick_ohlc(ax, ohlc.values, width=0.6, colorup='green', colordown='red', alpha=0.8)
# Setting labels & titles
ax.set_xlabel('Date')
ax.set_ylabel('Price')
fig.suptitle('Daily Candlestick Chart of INFY')
# Formatting Date
date_format = mpl_dates.DateFormatter('%d-%m-%Y')
ax.xaxis.set_major_formatter(date_format)
fig.autofmt_xdate()
fig.tight_layout()
plt.show()