2017-09-12 3 views
1

私は年、乗客のデータとその国の値を持つデータフレームを持っています。国はデータフレームから同じ考え方にとどまります。Pythonの値のテーブルのBoxplot

私はボックスプロットをプロットしようとしています。国:「USA」がx軸にあり、旅客データがy軸に表示されています。

が、私は得る:はAttributeError:「シリーズのオブジェクトが属性 '箱ひげ図' を持っていない

from matplotlib import pyplot as plt 
import pandas as pd 

df = pd.read_csv('CityPairs.csv') 

filt = (df.Country == 'USA') 
df = df[filt] 
reqcol = ['Year', 'Country', 'Passengers_Total'] 
df = df[reqcol] 

groupbyCountry = df.groupby(['Year', 'Country'])['Passengers_Total'].sum() 
groupbyCountry 

groupbyCountry.boxplot(column = 'Passengers_Total', by = 'Country') 

は、任意の助けを大幅にDataFrameため

答えて

1

使用reset_indexまたはパラメータas_index=Trueをいただければ幸いです。

groupbyCountry = df.groupby(['Year', 'Country'])['Passengers_Total'].sum().reset_index() 

または

groupbyCountry = df.groupby(['Year', 'Country'], as_index=False)['Passengers_Total'].sum() 

あなたが簡素化コーディングできる唯一のカテゴリ(USA)をploting場合:

groupbyCountry.boxplot(column = 'Passengers_Total') 
+1

それを行っているようです!それはタイマーが完了したときにそれを傷つける、歓声! – Liam