I am trying to fill a pandas dataframe NAN using random data of every column, and that random data appears in every column depeding on its frecuency. I have this:
def MissingRandom(dataframe):
import random
dataframe = dataframe.apply(lambda x: x.fillna(
random.choices(x.value_counts().keys(),
weights = list(x.value_counts()))[0]))
return dataframe
I get the DataFrame filled in with random data but its the same data for all the missing data of the column. I would like this data to be different for every missing of the column but I am not able to do it. Could anybody help me?
Thank you very much