📜  Python| Pandas Series.dt.is_quarter_start

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

Python| Pandas Series.dt.is_quarter_start

Series.dt可用于以 datetimelike 的形式访问系列的值并返回多个属性。 Pandas Series.dt.is_quarter_start属性返回一个布尔值,指示日期是否为季度的第一天。

示例 #1:使用Series.dt.is_quarter_start属性检查给定系列对象的基础数据中的日期是否是季度的第一天。

# importing pandas as pd
import pandas as pd
  
# Creating the Series
sr = pd.Series(['2012-4-1', '2019-7-18 12:30', '2008-02-2 10:30',
               '2010-4-22 09:25', '2019-1-1 00:00'])
  
# Creating the index
idx = ['Day 1', 'Day 2', 'Day 3', 'Day 4', 'Day 5']
  
# set the index
sr.index = idx
  
# Convert the underlying data to datetime 
sr = pd.to_datetime(sr)
  
# Print the series
print(sr)

输出 :

现在我们将使用Series.dt.is_quarter_start属性来检查给定系列对象中的日期是否是季度的第一天。

# check if dates are the first
# day of the quarter
result = sr.dt.is_quarter_start
  
# print the result
print(result)

输出 :

正如我们在输出中看到的, Series.dt.is_quarter_start属性已成功访问并返回布尔值,指示日期是否为季度的第一天。示例 #2:使用Series.dt.is_quarter_start属性检查给定系列对象的基础数据中的日期是否是季度的第一天。

# importing pandas as pd
import pandas as pd
  
# Creating the Series
sr = pd.Series(pd.date_range('2012-4-1 00:00',
                    periods = 5, freq = 'W'))
  
# 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.is_quarter_start属性来检查给定系列对象中的日期是否是季度的第一天。

# check if dates are the first
# day of the quarter
result = sr.dt.is_quarter_start
  
# print the result
print(result)

输出 :

正如我们在输出中看到的, Series.dt.is_quarter_start属性已成功访问并返回布尔值,指示日期是否为季度的第一天。