Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier.
Index.copy() function make a copy of this object. The function also sets the name and dtype attribute of the new object as that of original object. If we wish to have a different datatype for the new object then we can do that by setting the dtype attribute of the function.
Syntax: Index.copy(name=None, deep=False, dtype=None, **kwargs)
name : string, optional
deep : boolean, default False
dtype : numpy dtype or pandas type
Returns : copy : Index
Note : In most cases, there should be no functional difference from using deep, but if deep is passed it will attempt to deepcopy.
Example #1: Use
Index.copy() function to copy the Index value to a new object and change the datatype of new object to ‘int64’
Let’s create a copy of the object having ‘int64’ data type.
As we can see in the output, the function has returned a copy of the original Index with ‘int64’ dtype.
Example #2: Use
Index.copy() function to make a copy of the original object. Also set the name attribute of the new object and convert the string dtype into ‘datetime’ type.
Let’s make a copy of the original object.
As we can see in the output, the new object has the data in datatime format and its name attribute has also been set.
- Python | pandas.map()
- Python | Pandas TimedeltaIndex.take()
- Python | Pandas Series.abs()
- Python | Pandas dataframe.cov()
- Python | Pandas Series.dt.tz
- Python | Pandas Series.ptp()
- Python | Pandas Series.pop()
- Python | Pandas.to_datetime()
- Python | Pandas DatetimeIndex.second
- Python | Pandas DataFrame.loc
- Python | Pandas Series.ix
- Python | Pandas DatetimeIndex.day
- Python | Pandas Series.sum()
- Python | Pandas Period.day
- Python | Pandas TimedeltaIndex.max
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.