2017-03-26 118 views
1

我有一個熊貓數據集,我對兩列regionstotal_count感興趣。如何從數組中創建陰謀離線圖表?

def print_row(regionCount): 
    print regionCount['region'] 
    print regionCount['total_count'] 
regionCount.apply(print_row, axis = 1) 

輸出看起來如下:

Fribourg 
376 
Vallis 
608 
... 

在整個數據集,有與它們對應的TOTAL_COUNT 20米的區域。我想要描述酒吧欄的名稱和酒吧的高度。我怎樣才能建立一個圖表,從名單中獲取這些值,名稱爲regionCount

在下面的代碼,我想代替術語:foodserviceenvironment,也是數字:3.44.24.3regionCount['region'][0...end_of_regionCount]regionCount['total_count'][0...end_of_regionCount]分別。

plotly.offline.plot({ 
"data": [ 
    plotly.graph_objs.Bar(x=['food','service','environment'],y= 
[3.4,4.2,4.3]) 

], 

'layout': {'title': 'distribution', 
     'font': dict(family='Arial', size=16)}}, 
     auto_open=True, image = 'png', image_filename='plot_image', 
     output_type='file', image_width=800, image_height=600, filename='temp-plot.html', validate=False 
) 
+0

請,平均每個職位只有一個問題。 –

+0

已刪除。這是更多的一個修辭問題掛鉤第一個 –

+0

它可以解決使用:[http://stackoverflow.com/questions/32926202/read-the-values-from-the-print-statement-array-to-create -a-餅圖(http://stackoverflow.com/questions/32926202/read-the-values-from-the-print-statement-array-to-create-a-pie-chart) –

回答

0

不知道如果我有問題,其實你可以使用df.region的x值和df.total_count爲y值不作任何修改。

import pandas as pd 
import plotly 

df = pd.DataFrame({'region': ['Fribourg', 'Vallis', 'Geneva'], 
        'total_count': [376, 608, 555]}) 

plotly.offline.plot({"data": [plotly.graph_objs.Bar(x=df.region, 
           y=df.total_count)]}) 

enter image description here