Random row selection in Pandas dataframe
Is there a way to select random rows from a DataFrame in Pandas.
In R, using the car package, there is a useful function
some(x, n) which is similar to head but selects, in this example, 10 rows at random from x.
I have also looked at the slicing documentation and there seems to be nothing equivalent.
Now using version 20. There is a sample method.
Something like this?
import random def some(x, n): return x.ix[random.sample(x.index, n)]
★ Back to homepage or read more recommendations: