logo
Loading...

Day_008_dataFrame_operation 出 - Cupoy

您好,app_train.loc[0:10000, ['NAME_CONTRACT_TYPE', '...

ml100-2,dataframe,operation,ml100-2-d08

Day_008_dataFrame_operation 出

2019/04/24 07:15 上午
機器學習共學討論版
Chiamin Hsu
觀看數:1
回答數:1
收藏數:0
ml100-2
dataframe
operation
ml100-2-d08

您好,

app_train.loc[0:10000, ['NAME_CONTRACT_TYPE', 'AMT_INCOME_TOTAL', 'AMT_CREDIT', 'AMT_ANNUITY']].groupby(['NAME_CONTRACT_TYPE']).apply(lambda x: x / x.mean()) 

有 error. 我的 pandas 是 '0.20.3' 版本, 是因為作為 group index 的 'NAME_CONTRACT_TYPE' , 也被執行 x/x.mean() 嗎? 

..

TypeError: unsupported operand type(s) for /: 'str' and 'float'  During handling of the above exception, another exception occurred:  ValueError                                Traceback (most recent call last) <ipython-input-36-c914deb88e8f> in <module>()      1# 取前 10000 筆作範例: 分別將 AMT_INCOME_TOTAL, AMT_CREDIT, AMT_ANNUITY 除以根據 NAME_CONTRACT_TYPE 分組後的平均數,----> 2app_train.loc[0:10000,['NAME_CONTRACT_TYPE','AMT_INCOME_TOTAL','AMT_CREDIT','AMT_ANNUITY']].groupby(['NAME_CONTRACT_TYPE']).apply(lambda x: x / x.mean())~\Anaconda3\lib\site-packages\pandas\core\groupby.py in apply(self, func, *args, **kwargs)    714# ignore SettingWithCopy here in case the user mutates    715with option_context('mode.chained_assignment',None):--> 716return self._python_apply_general(f)    717    718def _python_apply_general(self, f):~\Anaconda3\lib\site-packages\pandas\core\groupby.py in _python_apply_general(self, f)