-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ENH add sample #2419 #7274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENH add sample #2419 #7274
Conversation
@@ -297,3 +297,20 @@ def _bucket_labels(series, k): | |||
mat[v] = i | |||
|
|||
return mat + 1 | |||
|
|||
|
|||
def choice(arr, size, replace): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
forgot that arr can be an int. Also, I should make the private.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't need this anymore since we require numpy 1.7 now
closing for now. @hayd if you want to update at some point, ok,. |
except ImportError: | ||
from pandas.stats.misc import choice | ||
msk = choice(len(self), size, replace=replace) | ||
return self.iloc[msk] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use take
, which is faster
Just wrote a little utility function to do this, so I may pick this up. def sample_n(df, size, replace=False, weight=None, seed=None):
rs = np.random.RandomState(seed)
locs = rs.choice(df.shape[0], size=size, replace=replace, p=weight)
return df.take(locs, axis=0) |
fixes #2419
Hmmm
np.random.choice
not available on numpy < 1.7.