combineというデータフレームがあり、Ageカラムにnull値があるので、「子供なら、子供の年齢の平均値で、そうでないなら大人の年齢の平均値」で埋めたいのですが、以下のように関数を定義しましたが、どこが間違えているのかわかりません。教えていただけると幸いです。
def fill_age(age): if combine["Age"].isnull(): if combine["person_child"]==1: combine["Age"] = combine.fillna(combine["Age"][combine["person_child"]==1].mean()) return combine["Age"] else: combine["Age"] = combine.fillna(combine["Age"][combine["person_child"]==0].mean()) return combine["Age"] else: return age combine["Age"] = combine["Age"].apply(fill_age) (エラーコード) The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。