0

I am trying to plug the predicted missing values into original df (of course to the column with missing value). How could I do so?

The predicted missing values are basically stored in a list/series whose length is the number of missing values in the original df. The order in the list matches with the order that missing values appear in the df, I think, since I split the test_set from the df using nonull() at the missing series.

I have been trying pd.Series.fillna, but that just allows one value to replace.

jpp
  • 159,742
  • 34
  • 281
  • 339
Hieu Tran
  • 31
  • 4

1 Answers1

0

You can use numpy where and pandas isnull function to do that.

df['relevant_column'] = np.where(df['relevant_column'].isnull(),
                                 predicted_values,
                                 df['relevant_column'])

predicted_values should be a pandas series or 1d numpy array with the same lenght as the dataframe.

P.Tillmann
  • 2,090
  • 10
  • 17