python - In-place version of pandas truncate? -


newbie question: there in-place version of pandas truncate?

for example

>>> df = pandas.dataframe({'stuff':range(5)}, index=range(5)) >>> df.truncate(2,3) 

returns new truncated data frame. do

>>> df = pandas.dataframe({'stuff':range(5)}, index=range(5)) >>> df = df.truncate(2,3) 

but seems inefficient. there way more efficient truncate not make copy truncate in-place? or kind of efficiency not issue due uber-clever pandas design?

note, docstring truncate says there copy option, not think affects whether dataframe truncated whether returned value copy of data frame or reference portion of data frame. see below mean:

>>> df = pandas.dataframe({'stuff':range(5)}, index=range(5)) >>> cp = df.truncate(2,3, copy=false) >>> df    stuff 0      0 1      1 2      2 3      3 4      4 >>> cp['stuff'][2] = -50 >>> df    stuff 0      0 1      1 2    -50 3      3 4      4 

notice when use copy=false df still not truncated returned object slice of df when modified modifies df.

thanks.

there no truncate in-place, inefficiency associated making copy can avoided using copy=false (if copy can avoided @ all, not case):

df = df.truncate(2,3, copy=false)

if keep reference original object remain unchanged though, discovered.

note in-place operations , copies unrelated. in-place operations can copy data , update internal reference while mnethods leave object unchanged not have copy data.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -