I am generating some random numbers and I am try to apply a condition that if values > 80 , then put None, but I am unable to get the results. My code is as follow
import pandas as pd
import numpy as np
from numpy import random
total = 200
rand_numbers = np.random.randint(0, 100, total)
corrupt_values = np.random.randint(0, 100, total) > 80
flag = False
if flag:
rand_numbers = [v for flag, v in zip(corrupt_values, rand_numbers)]
else:
rand_numbers = None
print 'rand_numbers: ', rand_numbers
I am trying to get results like
rand_numbers [20, 50, Nan, Nan, 40, 10] so that values greater than 80 are replaced by Nan
I am try to generate 200 random numbers in rand_numbers and then I am making a condition that if values exceeded than 80, then it will put NaN instead of values otherwise value. I am trying to zip these two arrays and making that condition to work, but I am struggling with it. I am new to coding. Any help would be greatly appreciated.