I am trying to assign 0 to random cells in a one dimensional pandas.DataFrame.
The below code is the best way I could think of doing this, however I believe there may be a neater approach to this problem.
import numpy as np
import pandas as pd
from random import randint
df = pd.DataFrame(np.random.randint(20, size=(10, 1)), columns=list('A'))
col_size = len(df.columns)
row_size = len(df.index)
df[df.columns[randint(0, col_size-1)]][randint(0, row_size-1)] = 0
Could someone please review and suggest if this is a good approach or there are better ways to do this?