Python Pandas TimedeltaIndex.to_series()

Python Pandas TimedeltaIndex.to_series()

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

Pandas TimedeltaIndex.to_series()函数创建一个索引和值都等于索引键的系列,与map一起用于返回基于索引的索引器。

语法:TimedeltaIndex.to_series(index = None, name = None)

参数 :
index :结果系列的索引。如果没有,默认为原始索引(Index,可选)。
name :结果系列的名称。如果没有,默认为原始索引的名称(字符串,可选)。

返回:系列:dtype将基于索引值的类型。

示例#1:使用TimedeltaIndex.to_series()函数从给定的TimedeltaIndex对象中构建一个系列对象。

# 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', '+23:29:59.999999',
                        '+12:19:59.999999'])
  
# Print the TimedeltaIndex object
print(tidx)
Python

输出 :
Python Pandas TimedeltaIndex.to_series()

现在我们将使用TimedeltaIndex.to_series()函数,用tidx构造一个系列对象。

# return a series
tidx.to_series()
Python

输出 :
Python Pandas TimedeltaIndex.to_series()

正如我们在输出中看到的,TimedeltaIndex.to_series()函数使用tidx对象返回了一个新构建的Series对象。注意该系列的索引也是使用给定对象的标签构建的。

示例#2:使用TimedeltaIndex.to_series()函数从给定的TimedeltaIndex对象构建一个系列对象。

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

输出 :
Python Pandas TimedeltaIndex.to_series()

现在我们将使用TimedeltaIndex.to_series()函数,用tidx构造一个系列对象。

# return a series
tidx.to_series()
Python

输出 :
Python Pandas TimedeltaIndex.to_series()
正如我们在输出中看到的,TimedeltaIndex.to_series()函数使用tidx对象返回了一个新构建的Series对象。注意该系列的索引也是使用给定对象的标签构建的。

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

Pandas 日期时间

登录

注册