아래 코드는 서로 다른 두 웹 사이트에서 데이터를 추출하고 Bokeh는 데이터를 플로팅합니다. 문제는 x 축에 datatime.now ()에 대해 "Volumes"데이터를 플롯 할 때 플롯되지만 "Open"또는 "Lasts"데이터를 플롯 할 때 Bokeh 플롯이 비어 있다는 것입니다. 스크랩 된 데이터에 가비지 문자가 포함되어 있다고 생각했지만 그렇다면 볼륨도 플로팅되지 않아야합니다. 이 문제는 출력을 tags1.text 및 tags2.text로 내보내는 "ugaz"및 "dgaz"에서도 발생합니다. 이해하려고 노력하고 있습니다.
그러나 내가 print (source.data) 출력이 나올 때
{ 'x': [datetime.datetime (2020, 1, 5, 21, 15, 38, 712611)], 'y': [ '1094'], 'y1': [ '2.095']}
코드는 다음과 같습니다.
import requests
from bs4 import BeautifulSoup
from bokeh.models import Range1d, LinearAxis
import time
from datetime import datetime
from bokeh.models import ColumnDataSource, DatetimeTickFormatter
from bokeh.plotting import figure, show
from math import radians
import pandas as pd
p = figure()
Volumes = []
Opens = []
Lasts=[]
Contracts =[]
Lows = []
Highs = []
res3 = requests.get('https://shared.websol.barchart.com/quotes/quote.php?
page=quote&sym=ng&x=13&y=8&domain=if&display_ice=1&enabled_ice_exchanges=&tz=0&ed=0')
res1 = requests.get('https://finance.yahoo.com/quote/ugaz?ltr=1')
res2 = requests.get('https://finance.yahoo.com/quote/dgaz?ltr=1')
soup1 = BeautifulSoup(res1.text,'html.parser')
soup2 = BeautifulSoup(res2.text,'html.parser')
tags1 = soup1.find_all('span')[11]
tags2 = soup2.find_all('span')[11]
soup3 = BeautifulSoup(res3.text, 'lxml')
soup3.prettify()
data_rows = soup3.findAll('tr')[2:]
i = range(len(data_rows))
for td in data_rows:
Volume = td.findAll('td')[6].text
Volumes.append(Volume)
Open = td.findAll('td')[3].text
Opens.append(Open)
Last = td.findAll('td')[1].text
Lasts.append(Last)
Contract = td.findAll('td')[0].text
Contracts.append(Contract)
Low = td.findAll('td')[5].text
Lows.append(Low)
High = td.findAll('td')[4].text
Highs.append(High)
source = ColumnDataSource(dict(x=[datetime.now()],y=[Volumes[2]], y1=[Opens[2]]))
p.circle(x ='x', y ='y',source=source,color='blue')
p.circle(x ='x', y ='y1',source=source,color='red')
show(p)
모든 값을 숫자로 변환하지 않습니다.
{
'x': [datetime.datetime(2020, 1, 5, 21, 15, 38, 712611)],
'y': ['1094'], # value in list is a string -- BAD
'y1': ['2.095'] # value in list is a string -- BAD
}
범주 형 값 (여기서는 해당되지 않음)을 구체적으로 표시하지 않는 한 CDS 열의 값은 일반적으로 항상 숫자 여야합니다.
내장 float
함수를 호출하여 문자열을 숫자로 변환 할 수 있습니다 .
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다