Python Pandas TimedeltaIndex.append()
Python是一种进行数据分析的伟大语言,主要是因为以数据为中心的Python包的奇妙生态系统。Pandas就是这些包中的一个,它使导入和分析数据变得更加容易。
Pandas TimedeltaIndex.append()函数将一个索引选项的集合追加到一起。通过以python列表或元组的形式传递索引,一次可以追加多个索引对象。
语法: TimedeltaIndex.append(other)
参数 :
其他 :索引或索引的列表/元组
返回 :附加的:索引
例子#1:使用TimedeltaIndex.append()函数在给定对象的末尾追加一个TimedeltaIndex对象。
# importing pandas as pd
import pandas as pd
# Create the first TimedeltaIndex object
tidx1 = pd.TimedeltaIndex(start ='1 days 02:00:12.001124', periods = 5,
freq ='N', name ='Koala')
# Create the second TimedeltaIndex object
tidx2 = pd.TimedeltaIndex(data =['-1 days 2 min 3us 10ns',
'1 days 06:05:01.000030',
'-1 days + 23:59:59.999999'])
# Print the first TimedeltaIndex object
print(tidx1)
# Print the second TimedeltaIndex object
print(tidx2)
输出 :
现在我们将在tidx1的末尾追加tidx2。
# append tidx2 at the end of tidx1
tidx1.append(tidx2)
输出 :
正如我们在输出中看到的,TimedeltaIndex.append()函数将tidx2附加在tidx1的末尾。
示例#2:使用TimedeltaIndex.append()函数在给定对象的末尾追加一个TimedeltaIndex对象的列表。
# importing pandas as pd
import pandas as pd
# Create the first TimedeltaIndex object
tidx1 = pd.TimedeltaIndex(start ='1 days 02:00:12.001124', periods = 5,
freq ='N', name ='Koala')
# Create the second TimedeltaIndex object
tidx2 = pd.TimedeltaIndex(data =['-1 days 2 min 3us 10ns',
'1 days 06:05:01.000030',
'-1 days + 23:59:59.999999'])
# Create the third TimedeltaIndex object
tidx3 = pd.TimedeltaIndex(data =['-3 days 02:10:00',
'1 days 06:05:01.000030',
'1 days 02:00:00'], name ='MyObjejct')
# Print the first TimedeltaIndex object
print(tidx1)
# Print the second TimedeltaIndex object
print(tidx2)
# Print the third TimedeltaIndex object
print(tidx3)
输出 :
现在我们将在tidx1的末尾追加tidx2和tidx3。
# append tidx2 and tidx3 at the end of tidx1
tidx1.append([tidx2, tidx3])
输出 :
正如我们在输出中看到的,TimedeltaIndex.append()函数在tidx1的末端追加了tidx2和tidx3。