给出一个熊猫时间戳:
> pd.Timestamp.now()
Timestamp('2015-09-02 19:33:55.714410')
如何在一小时内获得总分钟数(或秒数,或微秒数)? (作为总数的小数)。请注意,我并不是要求已经过了多少完整分钟(或秒或微秒)。
答案 0 :(得分:3)
t = pd.Timestamp.now()
(t - t.normalize()).total_seconds()
修改强>
获取小时内的总秒数:
t = pd.Timestamp.now()
(t - t.to_period("H").start_time).total_seconds()
答案 1 :(得分:1)
In [2]: t = Timestamp('2015-09-02 19:33:55.714410')
In [3]: t
Out[3]: Timestamp('2015-09-02 19:33:55.714410')
In [4]: t.hour
Out[4]: 19
In [6]: t.second
Out[6]: 55
In [7]: t.microsecond
Out[7]: 714410
In [8]: t.
t.asm8 t.dayofweek t.freqstr t.is_quarter_end t.isoweekday t.nanosecond t.resolution t.timetz t.today t.tzname t.week
t.astimezone t.dayofyear t.fromordinal t.is_quarter_start t.max t.normalize t.second t.to_datetime t.toordinal t.utcfromtimestamp t.weekday
t.combine t.days_in_month t.fromtimestamp t.is_year_end t.microsecond t.now t.strftime t.to_datetime64 t.tz t.utcnow t.weekofyear
t.ctime t.daysinmonth t.hour t.is_year_start t.min t.offset t.strptime t.to_julian_date t.tz_convert t.utcoffset t.year
t.date t.dst t.is_month_end t.isocalendar t.minute t.quarter t.time t.to_period t.tz_localize t.utctimetuple
t.day t.freq t.is_month_start t.isoformat t.month t.replace t.timetuple t.to_pydatetime t.tzinfo t.value
答案 2 :(得分:0)
import datetime as dt
In [63]:
last_hour = dt.datetime(t.year , t.month , t.day , t.hour , 0 , 0)
In [67]:
(t - last_hour).total_seconds()
Out[67]:
768.129