找到 34423 篇文章 关于编程

Python Pandas - 从 Period 对象检查年份是否为闰年

AmitDiwan
更新于 2021年10月14日 07:04:43

191 次浏览

要检查 Period 对象的年份是否为闰年,请使用 period.is_leap_year 属性。首先,导入所需的库 - import pandas as pd pandas.Period 表示一段时间。创建两个 Period 对象 period1 = pd.Period("2020-09-23 05:55:30") period2 = pd.Period(freq="Y", year = 2021, month = 7, day = 16, hour = 2, minute = 35) 显示 Period 对象 print("Period1...", period1) print("Period2...", period2) 检查年份是否为闰年 res1 = period1.is_leap_year res2 = period2.is_leap_year 示例 以下代码 import pandas as pd # pandas.Period 表示一段时间 # 创建两个 Period 对象 period1 = pd.Period("2020-09-23 ... 阅读更多

Python Pandas - 获取 Period 对象中一天的小时部分

AmitDiwan
更新于 2021年10月14日 07:02:54

94 次浏览

要获取 Period 对象中一天的小时部分,请使用 period.hour 属性。首先,导入所需的库 - import pandas as pd pandas.Period 表示一段时间。创建两个 Period 对象 - period1 = pd.Period("2020-09-23 05:55:30") period2 = pd.Period(freq="H", year = 2021, month = 7, day = 16, hour = 2, minute = 35) 从两个 Period 对象获取一天的小时 - res1 = period1.hour res2 = period2.hour 示例 以下代码 - import pandas as pd # pandas.Period 表示一段时间 # 创建两个 Period 对象 period1 = pd.Period("2020-09-23 05:55:30") period2 = pd.Period(freq="H", year ... 阅读更多

Python Pandas - 返回应用于给定 Period 对象的时间序列频率的字符串别名

AmitDiwan
更新于 2021年10月14日 07:01:10

84 次浏览

要返回应用于给定 Period 对象的时间序列频率的字符串别名,请使用 period.freqstr 属性。首先,导入所需的库 - import pandas as pd pandas.Period 表示一段时间。创建两个 Period 对象 - period1 = pd.Period("2020-09-23 03:55:20") period2 = pd.Period(freq="Y", year = 2021, month = 2, day = 14, hour = 2, minute = 35) 显示 Period 对象 - print("Period1...", period1) print("Period2...", period2) 获取频率的字符串别名 - res1 = period1.freqstr res2 = period2.freqstr 示例 以下代码 - import pandas as pd # pandas.Period 表示一段时间 # 创建两个 Period ... 阅读更多

Python Pandas - 查找给定 Period 对象的结束时间

AmitDiwan
更新于 2021年10月14日 06:59:32

173 次浏览

要查找给定 Period 对象的结束时间,请使用 period.end_time 属性。首先,导入所需的库 - import pandas as pd pandas.Period 表示一段时间。创建两个 Period 对象 - period1 = pd.Period("2020-09-23 03:55:20") period2 = pd.Period(freq="T", year = 2021, month = 2, day = 14, hour = 2, minute = 35) 显示 Period 对象 - print("Period1...", period1) print("Period2...", period2) 从两个 Period 对象获取结束时间 - res1 = period1.end_time res2 = period2.end_time 示例 以下代码 - import pandas as pd # pandas.Period 表示一段时间 # 创建两个 Period 对象 period1 = pd.Period("2020-09-23 03:55:20") ... 阅读更多

Python Pandas - 获取给定 Period 对象的频率

AmitDiwan
更新于 2021年10月14日 06:57:23

408 次浏览

要获取给定 Period 对象的频率,请使用 period.freq 属性。首先,导入所需的库 - import pandas as pd pandas.Period 表示一段时间。创建两个 Period 对象 - period1 = pd.Period("2020-09-23 03:55:20") period2 = pd.Period(freq="T", year = 2021, month = 2, day = 14, hour = 2, minute = 35) 显示 Period 对象 - print("Period1...", period1) print("Period2...", period2) 从两个 Period 对象获取频率 - res1 = period1.freq res2 = period2.freq 示例 以下代码 - import pandas as pd # pandas.Period 表示一段时间 # 创建两个 Period 对象 period1 = pd.Period("2020-09-23 03:55:20") period2 = pd.Period(freq="T", ... 阅读更多

Python Pandas - 形成两个索引对象的并集

AmitDiwan
更新于 2021年10月14日 06:55:11

108 次浏览

要形成两个索引对象的并集,请在 Pandas 中使用 index1.union(index2) 方法。首先,导入所需的库 - import pandas as pd 创建两个 Pandas 索引 - index1 = pd.Index([10, 20, 30, 40, 50]) index2 = pd.Index([80, 65, 60, 70, 55]) 显示 Pandas 索引 1 和索引 2 - print("Pandas Index1...", index1) print("Pandas Index2...", index2) 执行并集 - res = index1.union(index2) 示例 以下代码 - import pandas as pd # 创建两个 Pandas 索引 index1 = pd.Index([10, 20, 30, 40, 50]) index2 = pd.Index([80, 65, 60, 70, 55]) # 显示 Pandas 索引 1 和索引 2 print("Pandas Index1...", index1) print("Pandas Index2...", index2) # ... 阅读更多

Python Pandas - 获取 Period 对象所在的月份的天数总数

AmitDiwan
更新于 2021年10月14日 06:55:17

641 次浏览

要获取 Period 对象所在的月份的天数总数,请使用 period.daysinmonth 属性。首先,导入所需的库 - import pandas as pd pandas.Period 表示一段时间。创建两个 Period 对象 - period1 = pd.Period("2020-09-23") period2 = pd.Period(freq="D", year = 2021, month = 2, day = 14, hour = 2, minute = 35) 显示 Period 对象 - print("Period1...", period1) print("Period2...", period2) 从两个 Period 对象获取月份的天数 - res1 = period1.daysinmonth res2 = period2.daysinmonth 示例 以下代码 - import pandas as pd # pandas.Period 表示一段时间 # 创建两个 ... 阅读更多

Python Pandas - 形成两个索引对象的交集并对结果进行排序

AmitDiwan
更新于 2021年10月14日 06:52:58

567 次浏览

要形成两个索引对象的交集,请在 Pandas 中使用 index1.intersection(index2) 方法。要对结果进行排序,请使用 sort 参数。首先,导入所需的库 - import pandas as pd 创建 Pandas 索引 1 和索引 2 - index1 = pd.Index([4, 3, 2, 1]) index2 = pd.Index([8, 2, 6, 4]) 显示 Pandas 索引 1 和索引 2 print("Pandas Index1...", index1) print("Pandas Index2...", index2) 执行交集。使用“sort”参数对结果进行排序 res = index1.intersection(index2, sort=None) 示例 以下代码 - import pandas as pd # 创建 Pandas 索引 1 和索引 2 index1 = pd.Index([4, 3, 2, 1]) index2 = pd.Index([8, 2, 6, 4]) # 显示 ... 阅读更多

Python Pandas - 从 Period 对象获取一年中的某一天

AmitDiwan
更新于 2021年10月14日 06:52:27

153 次浏览

要从 Period 对象获取一年中的某一天,请使用 period.dayofyear 属性。首先,导入所需的库 - import pandas as pd pandas.Period 表示一段时间。创建两个 Period 对象 - period1 = pd.Period("2020-09-23") period2 = pd.Period(freq="D", year = 2021, month = 7, day = 16, hour = 2, minute = 35) 显示 Period 对象 - print("Period1...", period1) print("Period2...", period2) 从两个 Period 对象获取一年中的某一天 - res1 = period1.dayofyear res2 = period2.dayofyear 示例 以下代码 - import pandas as pd # pandas.Period 表示一段时间 # 创建两个 Period 对象 period1 = pd.Period("2020-09-23") period2 = ... 阅读更多

Python Pandas - 获取 Period 对象所在的星期几

AmitDiwan
更新于 2021年10月14日 06:51:33

108 次浏览

要获取 Period 对象所在的星期几,请使用 period.dayofweek 属性 首先,导入所需的库 - import pandas as pd pandas.Period 表示一段时间。创建两个 Period 对象 - period1 = pd.Period("2021-09-18") period2 = pd.Period(freq ='D', year = 2021, month = 9, day = 22, hour = 4, minute = 55) 显示 Period 对象 - print("Period1...", period1) print("Period2...", period2) 从两个 Period 对象获取星期几 - res1 = period1.dayofweek res2 = period2.dayofweek 示例 以下代码 - import pandas as pd # pandas.Period 表示一段时间 # 创建两个 Period 对象 period1 = ... 阅读更多

广告
© . All rights reserved.