Newbie question: is there an in-place version of pandas truncate?
For example
>>> df = pandas.DataFrame({'stuff':range(5)}, index=range(5))
>>> df.truncate(2,3)
returns a new truncated data frame. I could do
>>> df = pandas.DataFrame({'stuff':range(5)}, index=range(5))
>>> df = df.truncate(2,3)
but that seems inefficient. Is there a way to do a more efficient truncate which does not make a copy but does the truncate in-place? Or is this kind of efficiency not an issue due to some uber-clever pandas design?
Note, that the docstring for truncate says there is a copy option, but I do not think that affects whether the dataframe itself is truncated but whether the returned value is a copy of the data frame or a reference to a portion of the data frame. See below for what I 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 that when we use copy=False
df is still not truncated but the returned object is a slice of df which when modified also modifies df.
Thanks.