Getting Random rows in dataframe 1

Getting Random rows in dataframe

df = pandas.DataFrame(pandas.np.random.random(100))

# Randomly sample 70% of your dataframe
df_percent = df.sample(frac=0.7)

# Randomly sample 7 elements from your dataframe
df_elements = df.sample(n=7)

Here is what the above code is Doing:
1. Create a dataframe of 100 random numbers
2. Randomly sample 70% of the dataframe
3. Randomly sample 7 elements from the dataframe

Similar Posts