The goal is to fill the nan values in a column with a random number chosen from that same column.
I can do this one column as a time but when iterating through all the columns in the data frame I get a variety of errors. When I use "random.choice" I get letters rather than column values.
df1 = df_na
df2 = df_nan.dropna()
for i in range(5):
for j in range(len(df1)):
if np.isnan(df1.iloc[j,i]):
df1.iloc[j,i] = np.random.choice(df2.columns[i])
df1
Any suggestions on how to move forward?