0
我試圖繪製數據可以追溯到一路到1998年。「BokehUserWarning:ColumnDataSource的列必須具有相同的長度」
我的代碼的一個相當大的量似乎做工精細,但在運行時拋出錯誤消息「BokehUserWarning:ColumnDataSource的列必須具有相同的長度」
這裏是我的代碼:
import pandas as pd
from bokeh.io import show, output_file, gridplot
from bokeh.plotting import figure
#Create dataframe
df = pd.read_csv('/Users/macbook/Desktop/source.tab', names=[
'#','datesent','total','place'] delimiter='\t', header=None, encoding="ISO-8859-1")
#Format date
df['datesent'] = pd.to_datetime(df['datesent'], dayfirst=True)
#Datamunging
transactionssent = dict(pd.melt(df,value_vars=['datesent']).groupby('value').size())
transactionssent_dataframe = pd.DataFrame.from_dict(transactionssent, orient= 'index')
transactionssent_dataframe.columns = ['Number of sent transactions']
transactionssent_dataframe.index.rename('Date of sending', inplace= True)
#X- and Y-axis
x = pd.bdate_range('2017-1-1', '2200-1-1')
y = transactionssent_dataframe['Number of sent transactions']
#Bokeh object
ts = figure(x_axis_type="datetime")
#Show plot
ts.line(x, y)
output_file('/Users/macbook/Desktop/plot.html')
所有的輸出實際上是符合市場預期。錯誤是什麼意思?我真的必須從數據框中創建一個ColumndDataSource對象嗎? 我認爲直接將熊貓數據框傳遞給散景繪圖功能是獲得我想要的圖形的好方法。是否有從熊貓的日期框架創建散景圖的最佳做法?
感謝:
您可以通過一個數據幀直接創建ColumnDataSource。一切正常,現在沒有討厭的小警告。 –