-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Closed
Labels
API DesignNumeric OperationsArithmetic, Comparison, and Logical operationsArithmetic, Comparison, and Logical operations
Milestone
Description
I've realized the .sample()
function is sometimes returning a view rather than a copy. This will cause the "setting on a view/copy" error:
df = pd.DataFrame({'col1':[5,6,7], 'col2':['a','b','c']})
a_sample = df.sample(1)
a_sample['col1'] = 'z'
I believe the behavior is the result of it using the .take()
function, which is what the .sample()
command uses to pull the sample the passed frame.
I'd like to suggest either:
- replace
.take()
with.iloc()
- change
.take()
to.take().copy()
if that's faster (@shoyer suggested.take()
would be a faster -- is.take().copy()
?)
Thoughts?
Metadata
Metadata
Assignees
Labels
API DesignNumeric OperationsArithmetic, Comparison, and Logical operationsArithmetic, Comparison, and Logical operations