📜  Python|熊猫 DatetimeIndex.is_month_end

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

Python|熊猫 DatetimeIndex.is_month_end

Python是用于进行数据分析的出色语言,主要是因为以数据为中心的Python包的奇妙生态系统。 Pandas就是其中之一,它使导入和分析数据变得更加容易。

Pandas DatetimeIndex.is_month_end属性返回一个 numpy 数组,其中包含与 DatetimeIndex 对象中的每个条目对应的逻辑值。如果日期是该月的最后一天,则该值设置为True 。否则,该函数返回False ,表示日期不是该月的最后一天。

示例 #1:使用DatetimeIndex.is_month_end属性检查 DatetimeIndex 对象中存在的日期是否是该月的最后一天。

# importing pandas as pd
import pandas as pd
  
# Create the DatetimeIndex
didx = pd.DatetimeIndex(['2014-01-31', '2014-02-28', 
                         '2015-04-01', '2000-12-02'])
  
# Print the DatetimeIndex
print(didx)

输出 :

现在我们要查找给定 DatetimeIndex 对象中包含的日期是否是该月的最后一天。

# find if the days are the last day of the month.
didx.is_month_end

输出 :

正如我们在输出中看到的,该函数返回了一个 numpy 数组,其中包含 DatetimeIndex 对象的每个条目的逻辑值。 True值表示对应的日期是该月的最后一天, False值表示对应的日期不是该月的最后一天。示例 #2:使用DatetimeIndex.is_month_end属性检查 DatetimeIndex 对象中存在的日期是否是该月的最后一天。

# importing pandas as pd
import pandas as pd
  
# Create the DatetimeIndex
didx = pd.DatetimeIndex(start ='2000-01-31 06:30', freq ='BM', 
                             periods = 5, tz ='Asia/Calcutta')
  
# Print the DatetimeIndex
print(didx)

输出 :

现在我们要查找给定 DatetimeIndex 对象中包含的日期是否是该月的最后一天。

# find if the days are the last day of the month.
didx.is_month_end

输出 :

正如我们在输出中看到的,该函数返回了一个 numpy 数组,其中包含 DatetimeIndex 对象的每个条目的逻辑值。 True值表示对应的日期是该月的最后一天, False值表示对应的日期不是该月的最后一天。