pandas.DataFrame.at_time#

DataFrame.at_time(time, asof=False, axis=None)[source]#

选择一天中特定时间的值(例如,上午 9:30)。

参数:
timedatetime.time or str

要选择的值。

asofbool, default False

此参数目前不支持。

axis{0 或 ‘index’, 1 或 ‘columns’}, 默认为 0

对于 Series,此参数未使用,默认为 0。

返回:
Series 或 DataFrame

具有指定时间的值。

引发:
TypeError

如果索引不是 DatetimeIndex

另请参阅

between_time

选择一天中特定时间之间的值。

first

根据日期偏移量选择时间序列的初始周期。

last

根据日期偏移量选择时间序列的最终周期。

DatetimeIndex.indexer_at_time

获取一天中特定时间的值的索引位置。

示例

>>> i = pd.date_range("2018-04-09", periods=4, freq="12h")
>>> ts = pd.DataFrame({"A": [1, 2, 3, 4]}, index=i)
>>> ts
                     A
2018-04-09 00:00:00  1
2018-04-09 12:00:00  2
2018-04-10 00:00:00  3
2018-04-10 12:00:00  4
>>> ts.at_time("12:00")
                     A
2018-04-09 12:00:00  2
2018-04-10 12:00:00  4