w3resource

Pandas Series: at_time() function

Select all the values in a row at the particular time of the day

The at_time() function is used to select values at particular time of day (e.g. 10:30AM).

Syntax:

Series.at_time(self, time, asof=False, axis=None)
Pandas Series at_time image

Parameters:

Name Description Type/Default Value Required / Optional
time     datetime.time or str Required
axis For DataFrame, if not None, only use these columns to check for NaNs. {0 or ‘index’, 1 or ‘columns’}
Default Value: 0
Required

Returns: Series or DataFrame

Raises: TypeError
If the index is not a DatetimeIndex

Example:

Python-Pandas Code:

import numpy as np
import pandas as pd
i = pd.date_range('2019-04-09', periods=5, freq='12H')
ts = pd.DataFrame({'P': [2, 3, 4, 5, 6]}, index=i)
ts

Output:

                      P
2019-04-09 00:00:00	2
2019-04-09 12:00:00	3
2019-04-10 00:00:00	4
2019-04-10 12:00:00	5
2019-04-11 00:00:00	6
Pandas Series at_time image

Python-Pandas Code:

import numpy as np
import pandas as pd
i = pd.date_range('2019-04-09', periods=5, freq='12H')
ts = pd.DataFrame({'P': [2, 3, 4, 5, 6]}, index=i)
ts.at_time('12:00')

Output:

                      P
2019-04-09 12:00:00	3
2019-04-10 12:00:00	5

Previous: Localize tz-naive index of a Pandas Series
Next: Select values between particular times of the day



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/pandas/series/series-at_time.php