I am trying to plot data from Alpha Vantage.
JavaScript
x
2
1
data = pd.read_excel(file)
2
when I do
JavaScript
1
3
1
print(data.columns)
2
3
I get:
JavaScript
1
3
1
Index(['1. open', '2. high', '3. low', '4. close', '5.
2
adjusted close', '6. volume', dtype='object')
3
as you can see, ‘date’ is not on there. this is causing me problems when I start using mplfinance and matplotlib. Can anyone help?
ps: my excel sheet looks like this
date | 1. open … |
---|---|
2021-02-03 | 243 |
2021-02-02 | 245 |
Advertisement
Answer
Glancing at what you have shown as your excel file, it is possible that the data is backwards for mplfinance.
After data = pd.read_excel(file)
try this before calling mpf.plot()
:
data = data[::-1]
.
Then call mpf.plot(data)
Also, it looks like you have numbers in your column names:
JavaScript
1
3
1
Index(['1. open', '2. high', '3. low', '4. close', '5.
2
adjusted close', '6. volume', dtype='object')
3
(note: '1. open'
instead of 'open'
)
So try reassigning the column names:
Thus, this should work:
JavaScript
1
5
1
data = pd.read_excel(file)
2
data = data[::-1]
3
data.columns = ['open', 'high', 'low', 'close', 'adjusted close', 'volume']
4
mpf.plot(data)
5