[英]How can I fix the no value error in my code?
我正在嘗試使用 pandas 和 bokeh 使用 jupyter 讀取網站上的數據,但它返回 ValueError: no tables found 404 盡管鏈接有效。 任何提示將不勝感激。 以下是我的代碼行:
from math import pi
import pandas
from bokeh.plotting import figure, show, output_file
df = pandas.read_html("https://coinmarketcap.com/currencies/bitcoin/historical-data/?start=20190220&end=20190320")[2][::-1]
df["Date"] = pandas.to_datetime(df["Date"])
df.rename(index = str, columns = {"Open*": "Open"}, inplace = True)
df.rename(index = str, columns = {"Close**": "Close"}, inplace = True)
inc = df.Close > df.Open
dec = df.Open > df.Close
w = 12 * 60 * 60 * 1000
tools = "pan,wheel_zoom,box_zoom,reset,save"
p = figure(x_axis_type = "datetime", tools = tools, plot_width = 1200, title = "Bitcoin Candlesticks")
p.xaxis.major_label_orientation = pi / 4
p.grid.grid_line_alpha = 0.3
p.segment(df.Date, df.High, df.Date, df.Low, color = "black")
p.vbar(df.Date[inc], w, df.Open[inc], df.Close[inc], fill_color = "#D5E1DD", line_color = "black")
p.vbar(df.Date[dec], w, df.Open[dec], df.Close[dec], fill_color = "#F2583E", line_color = "black")
output_file("bitcoin.html", title = "Bitcoin Candlesticks")
show(p)
使用帶有標頭的requests
來獲取數據
url = 'https://finance.yahoo.com/quote/BTC-USD/history?period1=1577836800&period2=1609372800&interval=1d&filter=history&frequency=1d&includeAdjustedClose=true'
response = requests.get(url, headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'})
df = pd.read_html(response.text)[0][:-1]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.