python
1#map Fare value into groups of numerical values 2df_data["AgeBand"]=pd.qcut(df_data['Age'],8,labels=[1,2,3,4,5,6,7,8]).astype('int') 3 4df_train["AgeBand"]=pd.qcut(df_train['Age'],8,labels=[1,2,3,4,5,6,7,8]).astype('int') 5 6df_test["AgeBand"]=pd.qcut(df_test['Age'],8,labels=[1,2,3,4,5,6,7,8]).astype('int') 7 8df_train[["AgeBand","Survived"]].groupby(["AgeBand"],as_index=False).mean() 9print('AgeBand feature created')
ValueError Traceback (most recent call last)
<ipython-input-32-e2ea5911c9bb> in <module>()
1 #map Fare value into groups of numerical values
----> 2 df_data["AgeBand"]=pd.qcut(df_data['Age'],8,labels=[1,2,3,4,5,6,7,8]).astype('int')
3 df_train["AgeBand"]=pd.qcut(df_train['Age'],8,labels=[1,2,3,4,5,6,7,8]).astype('int')
4 df_test["AgeBand"]=pd.qcut(df_test['Age'],8,labels=[1,2,3,4,5,6,7,8]).astype('int')
5 df_train[["AgeBand","Survived"]].groupby(["AgeBand"],as_index=False).mean()
~\Anaconda3\lib\site-packages\pandas\core\reshape\tile.py in qcut(x, q, labels, retbins, precision, duplicates)
206 fac, bins = _bins_to_cuts(x, bins, labels=labels,
207 precision=precision, include_lowest=True,
--> 208 dtype=dtype, duplicates=duplicates)
209
210 return _postprocess_for_cut(fac, bins, retbins, x_is_series,
~\Anaconda3\lib\site-packages\pandas\core\reshape\tile.py in _bins_to_cuts(x, bins, right, labels, precision, include_lowest, dtype, duplicates)
232 raise ValueError("Bin edges must be unique: {bins!r}.\nYou "
233 "can drop duplicate edges by setting "
--> 234 "the 'duplicates' kwarg".format(bins=bins))
235 else:
236 bins = unique_bins
ValueError: Bin edges must be unique: array([ 0.17, 17. , 22. , 25. , 29. , 29. , 36. , 45. , 80. ]).
You can drop duplicate edges by setting the 'duplicates' kwarg
どうすれば良いですか?
誰か教えてください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/06/01 03:28
2018/06/01 03:29