Python 在尝试填充我的数据帧df';s";项目“U重量”;柱协议。至;项目“U标识符”。错误就要来了

Python 在尝试填充我的数据帧df';s";项目“U重量”;柱协议。至;项目“U标识符”。错误就要来了,python,python-3.x,dataframe,data-cleaning,fillna,Python,Python 3.x,Dataframe,Data Cleaning,Fillna,如果我是你,我会使用: avg_weight = df.pivot_table(index = "Item_Identifier",values = "Item_Weight") df_bool =df[df["Item_Weight"].isnull()] df.loc[df_bool,'Item_Weight'] = df.loc[df_bool,'Item_Identifier'].apply(lambda x: avg_weight[x]) 这将不会根据项目标识符的权重填充它,正如我在

如果我是你,我会使用:

avg_weight = df.pivot_table(index = "Item_Identifier",values = "Item_Weight")
df_bool =df[df["Item_Weight"].isnull()]
df.loc[df_bool,'Item_Weight'] = df.loc[df_bool,'Item_Identifier'].apply(lambda x: avg_weight[x])

这将不会根据项目标识符的权重填充它,正如我在代码中的透视表中所做的那个样。这将根据所有物品的平均重量填充。
df["Item_Weight"] = df["Item_Weight"].fillna(df["Item_Weight"].mean())