收到错误Timestamp object is not subscriptable.
我理解它的含义,但无法弄清楚如何解决代码。
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from mplfinance.original_flavor import candlestick_ohlc
API_URL = 'https://api.coingecko.com/api/v3'
r = requests.get(API_URL + '/coins/bitcoin/market_chart?vs_currency=usd&days=3&interval=hourly')
d = r.json()
df = pd.DataFrame(d['prices'], columns = ['dateTime', 'price'])
df['date'] = pd.to_datetime(df['dateTime'], unit='ms')
ohlc = df.set_index('date')['price'].resample('1h').ohlc()
stock_data = ohlc
class CandlesIndexes():
def __init__(self, stock_data):
self.high = stock_data.high
self.low = stock_data.low
self.close = stock_data.close
self.stock_data = stock_data
self.date = stock_data.index
def display_candle_bars(self):
fig, self.ax = plt.subplots()
#Describe candle properties
candle_ohlc = candlestick_ohlc(self.ax, self.date, width= 0.6, colorup= 'green', colordown= 'red', alpha= 0.8)
错误发生在最后candle_ohlc = candlestick_ohlc()
一行。
请帮助兄弟。谢谢,非常感谢。
编辑:完全错误:
File "/Users/teo/.local/share/virtualenvs/trend-nriNAUCq/lib/python3.8/site-packages/mplfinance/original_flavor.py", line 234, in candlestick_ohlc
return _candlestick(ax, quotes, width=width, colorup=colorup,
File "/Users/teo/.local/share/virtualenvs/trend-nriNAUCq/lib/python3.8/site-packages/mplfinance/original_flavor.py", line 283, in _candlestick
t, open, high, low, close = q[:5]
TypeError: 'Timestamp' object is not subscriptable```