Python是进行数据分析的一种出色语言, 主要是因为以数据为中心的python软件包具有奇妙的生态系统。大熊猫是这些软件包之一, 使导入和分析数据更加容易。
大熊猫Timestamp.date()函数返回与给定的Timestamp对象具有相同的年, 月和日的datetime对象。
语法:Timestamp.date()参数:无返回:date
示例1:采用Timestamp.date()函数将给定Timestamp对象的日期作为datetime对象返回。
# importing pandas as pd
import pandas as pd
# Create the Timestamp object
ts = pd.Timestamp(year = 2011 , month = 11 , day = 21 , hour = 10 , second = 49 , tz = 'US/Central' )
# Print the Timestamp object
print (ts)
输出:

现在我们将使用Timestamp.date()函数将日期作为datetime对象返回。
# return as a datetime object
ts.date()
输出:

正如我们在输出中看到的,
Timestamp.date()
函数已返回一个datetime对象, 该对象包含与给定Timestamp对象相同的年, 月和日。
示例2:
采用
Timestamp.date()
函数将给定Timestamp对象的日期作为datetime对象返回。
# importing pandas as pd
import pandas as pd
# Create the Timestamp object
ts = pd.Timestamp(year = 2009 , month = 5 , day = 31 , hour = 4 , second = 49 , tz = 'Europe/Berlin' )
# Print the Timestamp object
print (ts)
输出:

现在我们将使用Timestamp.date()函数将日期作为datetime对象返回。
# return as a datetime object
ts.date()
输出:

正如我们在输出中看到的, Timestamp.date()函数已返回一个datetime对象, 该对象包含与给定Timestamp对象相同的年, 月和日。
首先, 你的面试准备可通过以下方式增强你的数据结构概念:Python DS课程。
来源:
https://www.srcmini02.com/70223.html