i got curious as a beginner and a student about the python masking, so i made this code:
import numpy as np
import pandas as pd
import random
A = [123, 321, 213]
B = [456, 546, 654]
C = [789, 987, 879]
lst = {
"A":A,
"B":B,
"C":C}
df = pd.DataFrame(lst)
the code above produces this:
A B C0 123 456 789
1 321 546 987
2 213 654 879
and i made this code to mask the column:
df['A'].mask(df['A']>1, np.random.randint(1,3))
which now turns the values of column A into:
0 1
1 1
2 1
but i want a desired output to be like this:
0 2
1 3
2 1
any chance that it can be possible?, if so can you give me pointers?