Python Pandas PeriodIndex.day_in_month
Python是一种进行数据分析的伟大语言,主要是因为以数据为中心的Python软件包的奇妙生态系统。Pandas就是这些包中的一个,它使导入和分析数据更加容易。
Pandas PeriodIndex.days_in_month属性返回一个Index对象。该索引包含了给定PeriodIndex对象中每个元素在本月的天数。
语法 :
PeriodIndex.day_in_month
参数:无
示例#1:使用PeriodIndex.days_in_month属性来查找给定PeriodIndex对象中每个元素在本月的天数。
# importing pandas as pd
import pandas as pd
# Create the PeriodIndex object
pidx = pd.PeriodIndex(start ='2005-12-21',
end ='2005-12-29', freq ='D')
# Print the PeriodIndex object
print(pidx)
输出 :
现在我们将使用PeriodIndex.days_in_month属性来查找给定对象中每个元素在本月的天数。
# return the number of days in month
pidx.days_in_month
输出 :
正如我们在输出中看到的,PeriodIndex.days_in_month属性已经返回了一个Index对象,包含了给定PeriodIndex对象中每个元素在这个月的天数。
示例#2:使用PeriodIndex.days_in_month属性来查找给定PeriodIndex对象中每个元素在本月的天数。
# importing pandas as pd
import pandas as pd
# Create the PeriodIndex object
pidx = pd.PeriodIndex(start ='2011-02-14 ',
end ='2011-02-21', freq ='D')
# Print the PeriodIndex object
print(pidx)
输出 :
现在我们将使用PeriodIndex.days_in_month属性来查找给定对象中每个元素在本月的天数。
# return the number of days in month
pidx.days_in_month
输出 :
正如我们在输出中看到的,PeriodIndex.days_in_month属性已经返回了一个Index对象,包含了给定PeriodIndex对象中每个元素在这个月的天数。