Inputs are:
A Panda Dataframe with 500 columns and 10 lines, which contains a series of random integers comprised between 0 and 10000 (included)
A list of 10 random integers comprised between 0 and 10000
The output I am looking for is:
A Panda Dataframe with 500 columns and 10 lines, which gives the Boolean true or false depending if the element from the x-th line is above (true) or below (false) the number which is the x-th element of the list
I was able to solve this in excel using the following functions:
- =RANDARRAY(10,1,0,10000,TRUE)
- =IF(RANDARRAY(10,500,0,10000,TRUE)>A1,TRUE,FALSE)
Is there an elegant way of producing this solution in python? I am still a beginner learning more about python.
Thank you for the help
Update: Using MSS's solution, this is my final code. Could you please tell me if there are any mistakes in my code?
import numpy as np
import pandas as pd
import random
df = pd.DataFrame(np.random.randint(0,10000,size=(10, 500)))
df.head
list = random.sample(range(10000), 10)
print(list)
a = df.to_numpy()
b = np.array(list)
res = pd.DataFrame(a > b[:,None], index= df.index, columns=df.columns)
print(res)
Thank you for the help