2016-09-14 15 views
1

私はボックスプロットをプロットしようとしていますが、非形式属性エラーが発生しています。ボックスプロットのプロットを修正するにはどうすればよいですか?

どうすればいいですか?

マイコード:

Failed = train_df['Fees'][train_df['Passedornot'] == 0] 
Passed = train_df['Fees'][train_df['Passedornot'] ==1] 


average_fees = DataFrame([mean(Passed), mean(Failed)]) 
std_fees = DataFrame([standard_deviation(Passed), standard_deviation(Failed)]) 
fig, axis4 = plt.subplots(1,1) 
train_df['Fees'].plot(kind='hist', figsize=(15,5),bins=100, xlim=(0,30), ax=axis4) 


fig, axis5 = plt.subplots(1,1) 
average_fees.plot(kind='', legend=False, ax=axis5) 

エラー:データの

average_fees.plot(kind='bp', legend=False, ax=axis5) 
AttributeError: 'NoneType' object has no attribute 'plot' 

がサンプル:そこに何が起こるか

Name  Sex  Age Score Passedornot Fees 
    Tim Cole male 18 148   1  90 
    Ellen James female 47 143   1  80 
    Jerome Miles male 62 144   0  80 
    Waltz Albert male 27 153   0  90 

答えて

0

わからないが、私はあなたのaverage_feesが適切パンダはないと思いますデータフレーム。さらに、私のコンパイラはkind='bp'について不平を言っています。これは、コミュニティが常に完全に機能する実例を求めている理由の1つです。ここで

は、ファイルにsample.txtに保存されますが、提供されたデータの一部のため、Jupyterノートブックで実行するのpython3ための作業スニペット、次のとおりです。

import pandas as pd 
import numpy as np 
import matplotlib.pyplot as plt 
%matplotlib inline 
train_df = pd.read_csv('sample.txt', sep='\t') 
# train_df.head() 
Failed = train_df['Fees'][train_df['Passedornot'] == 0] 
Passed = train_df['Fees'][train_df['Passedornot'] == 1] 
average_fees = pd.DataFrame([np.mean(Passed), np.mean(Failed)]) 
std_fees = pd.DataFrame([np.std(Passed), np.std(Failed)]) 

fig1, axis4 = plt.subplots(1,1) 
n, bins, patches = plt.hist(train_df.Fees, 100, linewidth=1) 
plt.axis([0, 100, 0, 3]) 
plt.show() 

fig2, axis5 = plt.subplots(1,1) 
# print(type(average_fees)) 
average_fees.boxplot(return_type='axes') 
+0

ありがとう!私は関数のルートを作成しようとしていましたが、これははるかに優れています。私は1つのボックスプロットを得ることができましたが、これは2つを0と1としてプロットしていません。標準偏差で失敗し合格しましたか?どのように私はこれを変更することができますか? – Bolajio

+0

多分、あなたは 'train_df.boxplot(column = 'Fees'、= 'Passedornot'、return_type = 'axes')'のようなものを試すことができますか? 'by'を使ってデータを選択する基準を選択することができます。 'column = ...'をスキップすると、数値データを含むすべての行のいくつかのプロットが表示されます。 – nostradamus

関連する問題