我有以下問題,其中我的Python代碼不起作用。希望能提出一些建議,說明爲什麼以及如何解決。Python:在複雜數組上查找每行的多列搜索
這裏的例子數據框:
cust_id max_nibt nibt_0 nibt_1 nibt_10 line_0 line_1 line_10 11 200 -5 200 500 100 200 300 22 300 -10 100 300 100 200 300 33 400 -20 0 400 100 200 300
for i in range (0,11):
if (df4['nibt_%s' % i] == df4['max_nibt']):
df4['model_line'] = df4['line_%s' % i]
的代碼給我下面的錯誤:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()
然而,當我使用.any()
,它只是給了我最後的範圍內分配model_line = line_10。當我使用.all()
時,所有cust_ids的答案都是一樣的。想法?提前致謝。
這完美地工作!謝謝!。 – Timmy
太棒了!樂意效勞。當我從熊貓開始時,這個錯誤可能是我遇到的最常見的錯誤。請確認接受最有用的答案(勾選標記到旁邊)以確認解決方案(甚至可以幫助未來的讀者)。 – Parfait