Python Pandas TimedeltaIndex.copy

Python Pandas TimedeltaIndex.copy

Python是一种进行数据分析的伟大语言,主要是因为以数据为中心的Python包的奇妙生态系统。Pandas就是这些包中的一个,它使导入和分析数据变得更加容易。

Pandas TimedeltaIndex.copy()函数制作了这个TimedeltaIndex对象的副本。该函数还设置了新对象的Name和dtype属性

语法: TimedeltaIndex.copy(name=None, deep=False, dtype=None, **kwargs)

参数 :
name:字符串,可选
deep:布尔值,默认为假。
dtype : numpy dtype 或 pandas type

返回:复制:索引

例子#1:使用TimedeltaIndex.copy()函数对给定的TimedeltaIndex对象进行复制。

# importing pandas as pd
import pandas as pd
  
# Create the first TimedeltaIndex object
tidx = pd.TimedeltaIndex(start ='1 days 02:00:12.001124', periods = 5,
                                            freq ='N', name ='Koala')
  
# Print the TimedeltaIndex object
print(tidx)
Python

输出 :
Python Pandas TimedeltaIndex.copy

现在我们将使用TimedeltaIndex.copy()函数对tidx对象进行复制,并将复制的对象的名称设置为’New_koala’。

# make a copy and set the name
tidx_copy = tidx.copy(name ='New_koala')
  
# print the new object
print(tidx_copy)
Python

输出 :
Python Pandas TimedeltaIndex.copy
正如我们在输出中看到的,TimedeltaIndex.copy()函数对该对象进行了复制,该函数还设置了名称。

示例#2:使用TimedeltaIndex.copy()函数来检查所传递的标签是否存在于索引中。

# importing pandas as pd
import pandas as pd
  
# Create the TimedeltaIndex object
tidx = pd.TimedeltaIndex(data =['06:05:01.000030', '+23:59:59.999999',
                                       '22 day 2 min 3us 10ns', None])
  
# Print the TimedeltaIndex object
print(tidx)
Python

输出 :
Python Pandas TimedeltaIndex.copy

现在我们将使用TimedeltaIndex.copy()函数来复制tidx对象,并将复制的对象的名称设置为’New_koala’。我们还将把该对象的dtype改为str。

# make a copy, set the name and change the dtype
tidx_copy = tidx.copy(dtype ='str', name ='New_koala')
  
# print the new object
print(tidx_copy)
Python

输出 :
Python Pandas TimedeltaIndex.copy
我们可以在输出中看到,TimedeltaIndex.copy()函数已经复制了一个对象,同时也注意到新对象的dtype。

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

Pandas 日期时间

登录

注册