跳转至

Python | Pandas timestamp.is_year_start

原文:https://www.geesforgeks.org/python-pandas-timestamp-is_year_start/

Python 是进行数据分析的优秀语言,主要是因为以数据为中心的 python 包的奇妙生态系统。 【熊猫】 就是其中一个包,让导入和分析数据变得容易多了。

熊猫 **Timestamp.is_year_start**属性返回一个布尔值。如果给定时间戳对象中的日期是一年的开始,则返回True,否则返回False

语法: Timestamp.is_year_start

参数:

返回:布尔值

示例#1: 使用Timestamp.is_year_start属性检查给定时间戳对象中的日期是否是一年的开始。

# importing pandas as pd
import pandas as pd

# Create the Timestamp object
ts = pd.Timestamp(2016, 1, 1, 12)

# Print the Timestamp object
print(ts)

输出:

现在我们将使用Timestamp.is_year_start属性来检查 ts 对象中的日期是否是一年的开始。

# check if the date is the start of the year
ts.is_year_start

输出:

正如我们在输出中看到的那样,Timestamp.is_year_start属性返回了True,表示给定 Timestamp 对象中的日期是一年的开始。

示例#2: 使用Timestamp.is_year_start属性检查给定时间戳对象中的日期是否是年初。

# importing pandas as pd
import pandas as pd

# Create the Timestamp object
ts = pd.Timestamp(year = 2009, month = 5, day = 31,
                    hour = 4, tz = 'Europe/Berlin')

# Print the Timestamp object
print(ts)

输出:

现在我们将使用Timestamp.is_year_start属性来检查 ts 对象中的日期是否是一年的开始。

# check if the date is the start of the year
ts.is_year_start

输出:

正如我们在输出中看到的那样,Timestamp.is_year_start属性返回了False,表示给定 Timestamp 对象中的日期不是一年的开始。



回到顶部