pandas 构造时间值

70 篇文章 0 订阅
66 篇文章 1 订阅

在这里插入图片描述
pd.Timestamp pd.to_datetime(train[‘time’]) Property

Description

year

The year of the datetime

month

The month of the datetime

day

The days of the datetime

hour

The hour of the datetime

minute

The minutes of the datetime

second

The seconds of the datetime

microsecond

The microseconds of the datetime

nanosecond

The nanoseconds of the datetime

date

Returns datetime.date (does not contain timezone information)

time

Returns datetime.time (does not contain timezone information)

timetz

Returns datetime.time as local time with timezone information

dayofyear

The ordinal day of year

day_of_year

The ordinal day of year

weekofyear

The week ordinal of the year

week

The week ordinal of the year

dayofweek

The number of the day of the week with Monday=0, Sunday=6

day_of_week

The number of the day of the week with Monday=0, Sunday=6

weekday

The number of the day of the week with Monday=0, Sunday=6

quarter

Quarter of the date: Jan-Mar = 1, Apr-Jun = 2, etc.

days_in_month

The number of days in the month of the datetime

is_month_start

Logical indicating if first day of month (defined by frequency)

is_month_end

Logical indicating if last day of month (defined by frequency)

is_quarter_start

Logical indicating if first day of quarter (defined by frequency)

is_quarter_end

Logical indicating if last day of quarter (defined by frequency)

is_year_start

Logical indicating if first day of year (defined by frequency)

is_year_end

Logical indicating if last day of year (defined by frequency)

is_leap_year

Logical indicating if the date belongs to a leap year

pd.Timestamp
dates = pd.to_datetime(pd.Series([‘2022-7-10 13:14:55’, ‘2022-7-20’]), format=‘%Y-%m-%d %H:%M:%S’)
print(“返回日期值:”, dates.dt.date)
print(“返回时间:”, dates.dt.time)
print(“返回第几季度:”, dates.dt.quarter)
print(“返回年份:”, dates.dt.year)
print(“返回年中的第几天:”, dates.dt.dayofyear)
print(“返回年中的第几周:”, dates.dt.isocalendar().week)
print(“返回周几(0-6):”, dates.dt.dayofweek)
print(“返回具体的周几名称,如Friday:”, dates.dt.day_name())
print(“返回日期所在的月份总天数:”, dates.dt.days_in_month)

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值