📜  Python| Pandas Series.dt.微秒

📅  最后修改于: 2022-05-13 01:55:15.150000             🧑  作者: Mango

Python| Pandas Series.dt.微秒

Series.dt可用于以 datetimelike 的形式访问系列的值并返回多个属性。 Pandas Series.dt.microsecond属性返回一个 numpy 数组,其中包含给定系列对象的基础数据中日期时间的微秒。

示例 #1:使用Series.dt.microsecond属性返回给定 Series 对象的基础数据中日期时间的微秒。

# importing pandas as pd
import pandas as pd
  
# Creating the Series
sr = pd.Series(pd.date_range('2012-12-12 12:12',
                      periods = 5, freq = '5U'))
  
# Creating the index
idx = ['Day 1', 'Day 2', 'Day 3', 'Day 4', 'Day 5']
  
# set the index
sr.index = idx
  
# Print the series
print(sr)

输出 :

现在我们将使用Series.dt.microsecond属性在给定 Series 对象的基础数据中返回日期时间的微秒。

# return the microsecond
result = sr.dt.microsecond
  
# print the result
print(result)

输出 :

正如我们在输出中看到的, Series.dt.microsecond属性已成功访问并返回给定系列对象的基础数据中的日期时间的微秒。示例 #2:使用Series.dt.microsecond属性返回给定 Series 对象的基础数据中日期时间的微秒。

# importing pandas as pd
import pandas as pd
  
# Creating the Series
sr = pd.Series(pd.date_range('2008-2-9 08:20:21',
                       periods = 5, freq = '9U'))
  
# Creating the index
idx = ['Day 1', 'Day 2', 'Day 3', 'Day 4', 'Day 5']
  
# set the index
sr.index = idx
  
# Print the series
print(sr)

输出 :

现在我们将使用Series.dt.microsecond属性在给定 Series 对象的基础数据中返回日期时间的微秒。

# return the microsecond
result = sr.dt.microsecond
  
# print the result
print(result)

输出 :

正如我们在输出中看到的, Series.dt.microsecond属性已成功访问并返回给定系列对象的基础数据中的日期时间的微秒。