Pandas DataFrame copy() Method
Example
Make a copy of the data frame:
import pandas as pd
data = {
"name": ["Sally", "Mary",
"John"],
"qualified": [True, False, False]
}
df = pd.DataFrame(data)
#Make a copy:
newdf = df.copy()
print(newdf)
Try it Yourself »
Definition and Usage
The copy()
method returns a copy of the DataFrame.
By default, the copy is a "deep copy" meaning that any changes made in the original DataFrame will NOT be reflected in the copy.
Note:
With the parameter deep=False
, it is only the
reference to the data (and index) that will be copied, and any changes made in the
original will be reflected in the copy, and, any changes
made in the copy will be reflected in the original.
Syntax
dataframe.copy(deep)
Parameters
The parameter is a keyword argument.
Parameter | Value | Description |
---|---|---|
deep | True|False | Optional. Default True. Specifies whether to make a deep or a shallow copy.
By default (
With the parameter |
Return Value
a Pandas DataFrame as a copy of the original.