2017-06-29 88 views
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對象嗎? 我認爲直接將熊貓數據框傳遞給散景繪圖功能是獲得我想要的圖形的好方法。是否有從熊貓的日期框架創建散景圖的最佳做法?

回答

2

我假設驗證錯誤來自您的xy系列的長度不同。如果有意義的話,輸出可能會切斷較長陣列的懸垂部分。

您不必「手動」創建ColumnDataSource(當您將數組傳遞給像line這樣的字形方法時,它會在內部創建),但它有一些有助於防止這種情況的驗證內容。

source = ColumnDataSource(dataframe) 
ts.line(x='x', y='y', source=source) 
+0

感謝:

您可以通過一個數據幀直接創建ColumnDataSource。一切正常,現在沒有討厭的小警告。 –

相關問題