根據下面的代碼編寫了一個二進制變量編碼問題。如果feature
小於或等於30,我想變量metric
爲1,否則爲0。當我運行這段代碼,我得到了以下錯誤:ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
嘗試基於條件語句對二進制變量進行編碼
if df1.Feature <= 30:
df1.metric=1
else:
df1.metric=0
我猜錯誤代碼行沒有發佈。我看不到'a'變量。 – danihp
[系列的真值可能不明確。使用a.empty,a.bool(),a.item(),a.any()或a.all()](https://stackoverflow.com/questions/32699034/the-truth-value-of- a-series-is-ambiguous-use-a-empty-a-bool-a-item-a-any) – ppperry
這讓我很困惑,沒有任何對象,我導入了我的庫(numpy/pandas )和數據並嘗試創建變量REC30PY – mitch