-1
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])
falsetru
  • 357,413
  • 63
  • 732
  • 636

1 Answers1

0

I would use fillna if I were you:

df["Item_Weight"] = df["Item_Weight"].fillna(df["Item_Weight"].mean())
O.Suleiman
  • 898
  • 1
  • 6
  • 11
  • that will not fill it according to weight of item identifier as I have in pivot table in the code. This will fill it according to average weight of all the items. – Namish Singh Dec 07 '17 at 10:52