当前位置: 首页 > news >正文

Python酷库之旅-第三方库Pandas(160)

目录

一、用法精讲

731、pandas.Period.dayofyear属性

731-1、语法

731-2、参数

731-3、功能

731-4、返回值

731-5、说明

731-6、用法

731-6-1、数据准备

731-6-2、代码示例

731-6-3、结果输出

732、pandas.Period.day_of_year属性

732-1、语法

732-2、参数

732-3、功能

732-4、返回值

732-5、说明

732-6、用法

732-6-1、数据准备

732-6-2、代码示例

732-6-3、结果输出

733、pandas.Period.days_in_month属性

733-1、语法

733-2、参数

733-3、功能

733-4、返回值

733-5、说明

733-6、用法

733-6-1、数据准备

733-6-2、代码示例

733-6-3、结果输出

734、pandas.Period.daysinmonth属性

734-1、语法

734-2、参数

734-3、功能

734-4、返回值

734-5、说明

734-6、用法

734-6-1、数据准备

734-6-2、代码示例

734-6-3、结果输出

735、pandas.Period.end_time属性

735-1、语法

735-2、参数

735-3、功能

735-4、返回值

735-5、说明

735-6、用法

735-6-1、数据准备

735-6-2、代码示例

735-6-3、结果输出

二、推荐阅读

1、Python筑基之旅

2、Python函数之旅

3、Python算法之旅

4、Python魔法之旅

5、博客个人主页

一、用法精讲

731、pandas.Period.dayofyear属性
731-1、语法
# 731、pandas.Period.dayofyear属性
pandas.Period.dayofyear
Return the day of the year.This attribute returns the day of the year on which the particular date occurs. The return value ranges between 1 to 365 for regular years and 1 to 366 for leap years.Returns:
int
The day of year.
731-2、参数

        无

731-3、功能

        可以用来获取某个周期(Period)在一年中的第几天,它主要用于处理时间序列数据时,特别是当你需要提取时间信息时。

731-4、返回值

        返回值是一个整数,表示该周期在其年份中的第几天。例如:

  • 对于一个代表2023年1月1日的周期,dayofyear将返回1。
  • 对于一个代表2023年12月31日的周期,dayofyear将返回365(对于非闰年)或366(对于闰年)。
731-5、说明

        无

731-6、用法
731-6-1、数据准备
731-6-2、代码示例
# 731、pandas.Period.dayofyear属性
import pandas as pd
# 创建一个Period对象
period = pd.Period('2024-10-22')
# 获取该周期在一年中的第几天
day_of_year = period.dayofyear
print(day_of_year)
731-6-3、结果输出
# 731、pandas.Period.dayofyear属性
# 296
732、pandas.Period.day_of_year属性
732-1、语法
# 732、pandas.Period.day_of_year属性
pandas.Period.day_of_year
Return the day of the year.This attribute returns the day of the year on which the particular date occurs. The return value ranges between 1 to 365 for regular years and 1 to 366 for leap years.Returns:
int
The day of year.
732-2、参数

        无

732-3、功能

        用于获取一个Period对象(比如一个月份、一个星期或一年等)在该年中对应的天数,对于需要分析时间序列数据的用户非常有用,特别是在与年度数据进行比较时。

732-4、返回值

        返回值是一个整数,表示该时间周期在一年中的天数。例如:

  • 对于2024-01-01,返回值为1(因为它是该年的第一天)。
  • 对于2024-12-31,返回值为365(在非闰年的情况下)。
  • 对于2月28日,返回值为59(在非闰年情况下)。
732-5、说明

        无

732-6、用法
732-6-1、数据准备
732-6-2、代码示例
# 732、pandas.Period.day_of_year属性
import pandas as pd
# 创建一个时间周期
period = pd.Period('2024-10-22')
# 获取该周期在一年中的天数
day_of_year = period.day_of_year
print(day_of_year)  
732-6-3、结果输出
# 732、pandas.Period.day_of_year属性
# 296
733、pandas.Period.days_in_month属性
733-1、语法
# 733、pandas.Period.days_in_month属性
pandas.Period.days_in_month
Get the total number of days in the month that this period falls on.Returns:
int
733-2、参数

        无

733-3、功能

        用于获取一个时间周期所在的月份的天数。

733-4、返回值

        返回值是一个整数,表示该月份的总天数:

  • 对于1月、3月、5月、7月、8月、10月和12月,返回值为31天。
  • 对于4月、6月、9月和11月,返回值为30天。
  • 对于2月,返回值通常是28天,但在闰年时为29天。
733-5、说明

        无

733-6、用法
733-6-1、数据准备
733-6-2、代码示例
# 733、pandas.Period.days_in_month属性
import pandas as pd
# 创建一个表示2024年10月的Period对象
period = pd.Period('2024-10', freq='M')
# 获取该月份的天数
days_in_month = period.days_in_month
print(days_in_month)
733-6-3、结果输出
# 733、pandas.Period.days_in_month属性
# 31
734、pandas.Period.daysinmonth属性
734-1、语法
# 734、pandas.Period.daysinmonth属性
pandas.Period.daysinmonth
Get the total number of days of the month that this period falls on.Returns:
int
734-2、参数

        无

734-3、功能

        用于获取该Period对象所代表的月份中的天数。

734-4、返回值

        返回值是一个整数,表示该月份的总天数:

  • 对于1月、3月、5月、7月、8月、10月和12月,返回值为31天。
  • 对于4月、6月、9月和11月,返回值为30天。
  • 对于2月,返回值通常是28天,但在闰年时为29天。
734-5、说明

        无

734-6、用法
734-6-1、数据准备
734-6-2、代码示例
# 734、pandas.Period.daysinmonth属性
import pandas as pd
# 创建一个Period对象
period = pd.Period('2024-10')
# 获取该月的天数
days = period.daysinmonth
print(f"2024年10月有{days}天")
# 检查闰年2月
leap_feb = pd.Period('2024-02')
print(f"2024年2月有{leap_feb.daysinmonth}天")
734-6-3、结果输出
# 734、pandas.Period.daysinmonth属性
# 2024年10月有31天
# 2024年2月有29天
735、pandas.Period.end_time属性
735-1、语法
# 735、pandas.Period.end_time属性
pandas.Period.end_time
Get the Timestamp for the end of the period.Returns:
Timestamp
735-2、参数

        无

735-3、功能

        用于获取该周期的结束时间。

735-4、返回值

        返回一个Timestamp对象,表示该周期的结束时间。

735-5、说明

        无

735-6、用法
735-6-1、数据准备
735-6-2、代码示例
# 735、pandas.Period.end_time属性
import pandas as pd
# 创建一个Period对象
period_month = pd.Period('2024-10', freq='M')
# 获取该周期的结束时间
end_time_month = period_month.end_time
print(f"2024年10月的结束时间是: {end_time_month}")
# 创建一个Period对象表示一天
period_day = pd.Period('2024-10-22', freq='D')
# 获取该周期的结束时间
end_time_day = period_day.end_time
print(f"2024年10月22日的结束时间是: {end_time_day}")
735-6-3、结果输出
# 735、pandas.Period.end_time属性
# 2024年10月的结束时间是: 2024-10-31 23:59:59.999999999
# 2024年10月22日的结束时间是: 2024-10-22 23:59:59.999999999

二、推荐阅读

1、Python筑基之旅
2、Python函数之旅
3、Python算法之旅
4、Python魔法之旅
5、博客个人主页

http://www.mrgr.cn/news/56401.html

相关文章:

  • nosql课本习题
  • PLL锁相环带宽定义,以及PI参数自动整定
  • Unity学习记录-API
  • AutoSar AP CM实例说明符的使用方法总结
  • 【存储设备专栏 2.4 -- linux 下块设备格式化命令详细介绍】
  • 浏览器控制的无线开关
  • Linux基础命令(入门)
  • Java框架之MyBatis Plus
  • linux介绍与基本指令
  • Linux系统基础-进程间通信(2)_命名管道和System V通信
  • 【linux】线程 (三)
  • python虚拟环境安装
  • [LeetCode] 814. 二叉树剪枝
  • github加速 DevSidecar 1.8.8
  • 免费送源码:Java+ssm+MySQL SSM二手物品管理系统 计算机毕业设计原创定制
  • AutoSar AP CM实例说明符的使用方法总结
  • 开头的例子的理解
  • 【系统规划与管理师】历年各章节分值汇总(论文)
  • C++ 进阶:类相关特性的深入探讨
  • 伺服增量式和绝对式的本质区别?
  • 基因检测4 - 多囊肾
  • flask服务通过gunicorn启动,supervised管理服务
  • 基于Java+ssm的名著阅读网站
  • HTTP 请求中的Content-Type
  • ECHO-GL:盈利电话驱动的异质图学习股票 走势预测
  • HTB:Headless[WriteUP]