cudf.DataFrame.copy#
- DataFrame.copy(deep: bool = True) Self[source]#
Make a copy of this object’s indices and data.
When
deep=True(default), a new object will be created with a copy of the calling object’s data and indices. Modifications to the data or indices of the copy will not be reflected in the original object (see notes below). Whendeep=False, a new object will be created without copying the calling object’s data or index (only references to the data and index are copied). Data is shared via copy-on-write, so modifications to either object will trigger a physical copy and will not be reflected in the other.- Parameters:
- deepbool, default True
Make a deep copy, including a copy of the data and the indices. With
deep=Falseneither the indices nor the data are copied.
- Returns:
- copySeries or DataFrame
Object type matches caller.
Examples
>>> s = cudf.Series([1, 2], index=["a", "b"]) >>> s a 1 b 2 dtype: int64 >>> s_copy = s.copy() >>> s_copy a 1 b 2 dtype: int64
Shallow copy versus default (deep) copy:
>>> s = cudf.Series([1, 2], index=["a", "b"]) >>> deep = s.copy() >>> shallow = s.copy(deep=False)
Shallow copy shares data via copy-on-write. Modifications to either the original or the shallow copy trigger a physical copy, so changes are not reflected in the other.
>>> s['a'] = 3 >>> shallow['b'] = 4 >>> s a 3 b 2 dtype: int64 >>> shallow a 1 b 4 dtype: int64 >>> deep a 1 b 2 dtype: int64