2017-11-22 7 views
0

도움을 주신 데 대해 대단히 감사드립니다. 기계 학습을위한 클래식 Kaggle Titanic 튜토리얼에 문제가 있습니다. dataframe의 수단 (또는 tupple를) imput하는 중추적 인 표를 사용하면 내 문제는 다음과 같습니다Python : (타이타닉) 요금 반입시 디버깅 오류

fare_means = df.pivot_table("Fare", index= "Pclass", aggfunc="mean") 

​fare_means.info()  
fare_class 'pandas.core.frame.DataFrame'>  
Int64 
Index: 3 entries, 1 to 3  
Data columns (total 1 columns): Fare 3 non-null float64 
dtypes: float64(1) 
memory usage: 48.0 bytes 

fare_means 
Out[46]: 
Fare ---Pclass  
1  ------- 84.154687 
2  -------20.662183 
3  -------13.675550 

df_test['Fare'] = df_test[['Fare', 'Pclass']].apply(lambda x: 

fare_means[x['Pclass']] if pd.isnull(x['Fare']) 

else x['Fare'], axis=1) 

KeyError를 (3 인덱스 152 '에 u'occurred) 나는 그것을 분류 한

df_test.iloc[150:155, 0: ] 
    Index-- Pclass ---- Fare  
    150 ------ 1  --------83.1583 
    151 ------ 3  --------7.8958  
    152 ------ 3  --------NaN  
    153 ------ 3  --------12.1833 
    154 ------ 3  --------31.3875 

답변

0

밖으로 문제가 중요한 테이블이 기차 = pd.read_csv ('.../kaggletrain')

테스트 = pd.read_csv ('.../kaggletest이 `수입 팬더처럼 인덱싱 할 필요가 있다는 것입니다 ')

,

fare_means train.pivot_table = ('요금'인덱스 = 'Pclass'aggfunc = '평균')

fare_means [1 : 2]

따라서

시험 [ '요금'] = int (x [ 'Pclass'])] if pd.isnull (x [ 'Pclass'] - 1) : if (x [ 'Pclass']) 'Fare']) else x [ 'Fare'], 축 = 1) '