Python| Pandas TimedeltaIndex.insert
Python是一种用于进行数据分析的出色语言,主要是因为以数据为中心的Python包的奇妙生态系统。 Pandas就是其中之一,它使导入和分析数据变得更加容易。
Pandas TimedeltaIndex.insert()
函数将基础数据作为给定 TimedeltaIndex 对象的 ndarray 返回。
Syntax : TimedeltaIndex.insert(loc, item)
Parameters :
loc : int
item : if not either a Python datetime or a numpy integer-like, returned Index dtype will be object rather than datetime.
Return : new_index : Index
示例 #1:使用TimedeltaIndex.insert()
函数用于在 TimedeltaIndex 对象中插入新值。它返回一个新对象,在所需位置插入了新元素。
# importing pandas as pd
import pandas as pd
# Create the TimedeltaIndex object
tidx = pd.TimedeltaIndex(data =['3 days 06:05:01.000030', '1 days 06:05:01.000030',
'3 days 06:05:01.000030', '1 days 02:00:00',
'21 days 06:15:01.000030'])
# Print the TimedeltaIndex object
print(tidx)
输出 :
现在我们将使用TimedeltaIndex.insert()
函数在第 0 个位置插入一个值
# insert the passed value at 0th position
tidx.insert(loc = 0, item ='4 days 06:05:01.000030')
输出 :
正如我们在输出中看到的, TimedeltaIndex.insert()
函数已将传递的值插入到 tidx 对象的所需位置。示例 #2:使用TimedeltaIndex.insert()
函数用于在 TimedeltaIndex 对象中插入新值。它返回一个新对象,在所需位置插入了新元素。
# importing pandas as pd
import pandas as pd
# Create the TimedeltaIndex object
tidx = pd.TimedeltaIndex(data =['06:05:01.000030', '3 days 06:05:01.000030',
'22 day 2 min 3us 10ns', '+23:59:59.999999',
'13 days 06:05:01.000030', '+12:19:59.999999'])
# Print the TimedeltaIndex object
print(tidx)
输出 :
现在我们将使用TimedeltaIndex.insert()
函数在第 0 个位置插入一个值
# insert the passed value at 0th position
tidx.insert(loc = 0, item ='100 days 08:11:01.000030')
输出 :
正如我们在输出中看到的, TimedeltaIndex.insert()
函数已将传递的值插入到 tidx 对象的所需位置。