讓我們以一個例子與這個簡單的數據集:Lambda表達式語法錯誤與如果
example_set = pd.DataFrame(data = {"dirr":[1,0,-1,-1,1,-1,0],
"value": [125,130,80,8,150,251,18],
"result":[np.NaN for _ in range(7)]})
下面一行返回error:invalid syntax
example_set["result"].apply(lambda x : example_set["value"]if x["dirr"]==1)
誰能告訴我什麼,我做錯了什麼? 請不要拿出解決方案,如何做到這一點沒有lambda
:這只是一個超級簡化的例子,我彌補了我的問題。
@EdChum請完整閱讀這個問題:*請不要拿出解決方案如何做到這一點沒有lambda表達式:這只是一個超級簡化的例子,我已經彌補了我的問題。* –
'.apply(lambda x :example_set [「value」] if x [「dirr」] == 1 else x)'? – MYGz
@MYGz這會返回另一個錯誤:'TypeError:'float'object is not subscriptable' –