im tring to applay mnar missing patter to a dataframe with this python code
values = dataframe[column].unique()
value = np.random.choice(values)
index = dataframe[dataframe[column] == value].index
n_rows_to_delate = int(len(dataframe) * missing_ratio)
index_to_delate = np.random.choice(index, numero_righe_da_canellare, replace=True)
index_to_delate.sort()
dataframe.loc[index_to_delate, column] = np.nan
All works well until dataframe.loc.
I expect this function to delete all the indices in the index_to_delete list, but it only deletes some of them and I really can’t understand why. The column from which I’m trying to delete the data contains only 0 and 1.
thx
New contributor
Isaia Del Rosso is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1