|
11 | 11 | """ |
12 | 12 | from __future__ import annotations |
13 | 13 |
|
| 14 | +import datetime |
14 | 15 | from typing import Hashable, Iterable, Literal, Optional, Sequence, Union |
15 | 16 |
|
16 | 17 | from bigframes_vendored import constants |
@@ -4734,6 +4735,85 @@ def merge( |
4734 | 4735 | """ |
4735 | 4736 | raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE) |
4736 | 4737 |
|
| 4738 | + def resample( |
| 4739 | + self, |
| 4740 | + rule: str, |
| 4741 | + *, |
| 4742 | + closed: Optional[Literal["right", "left"]] = None, |
| 4743 | + label: Optional[Literal["right", "left"]] = None, |
| 4744 | + on=None, |
| 4745 | + level=None, |
| 4746 | + origin: Union[ |
| 4747 | + Union[pd.Timestamp, datetime.datetime, np.datetime64, int, float, str], |
| 4748 | + Literal["epoch", "start", "start_day", "end", "end_day"], |
| 4749 | + ] = "start_day", |
| 4750 | + ): |
| 4751 | + """Resample time-series data. |
| 4752 | +
|
| 4753 | + **Examples:** |
| 4754 | +
|
| 4755 | + >>> import bigframes.pandas as bpd |
| 4756 | + >>> data = { |
| 4757 | + ... "timestamp_col": pd.date_range( |
| 4758 | + ... start="2021-01-01 13:00:00", periods=30, freq="1s" |
| 4759 | + ... ), |
| 4760 | + ... "int64_col": range(30), |
| 4761 | + ... "int64_too": range(10, 40), |
| 4762 | + ... } |
| 4763 | +
|
| 4764 | + Resample on a DataFrame with index: |
| 4765 | +
|
| 4766 | + >>> df = bpd.DataFrame(data).set_index("timestamp_col") |
| 4767 | + >>> df.resample(rule="7s").min() |
| 4768 | + int64_col int64_too |
| 4769 | + 2021-01-01 12:59:55 0 10 |
| 4770 | + 2021-01-01 13:00:02 2 12 |
| 4771 | + 2021-01-01 13:00:09 9 19 |
| 4772 | + 2021-01-01 13:00:16 16 26 |
| 4773 | + 2021-01-01 13:00:23 23 33 |
| 4774 | + <BLANKLINE> |
| 4775 | + [5 rows x 2 columns] |
| 4776 | +
|
| 4777 | + Resample with column and origin set to 'start': |
| 4778 | +
|
| 4779 | + >>> df = bpd.DataFrame(data) |
| 4780 | + >>> df.resample(rule="7s", on = "timestamp_col", origin="start").min() |
| 4781 | + int64_col int64_too |
| 4782 | + 2021-01-01 13:00:00 0 10 |
| 4783 | + 2021-01-01 13:00:07 7 17 |
| 4784 | + 2021-01-01 13:00:14 14 24 |
| 4785 | + 2021-01-01 13:00:21 21 31 |
| 4786 | + 2021-01-01 13:00:28 28 38 |
| 4787 | + <BLANKLINE> |
| 4788 | + [5 rows x 2 columns] |
| 4789 | +
|
| 4790 | + Args: |
| 4791 | + rule (str): |
| 4792 | + The offset string representing target conversion. |
| 4793 | + Offsets 'ME', 'YE', 'QE', 'BME', 'BA', 'BQE', and 'W' are *not* |
| 4794 | + supported. |
| 4795 | + closed (Literal['left'] | None): |
| 4796 | + Which side of bin interval is closed. The default is 'left' for |
| 4797 | + all supported frequency offsets. |
| 4798 | + label (Literal['right'] | Literal['left'] | None): |
| 4799 | + Which bin edge label to label bucket with. The default is 'left' |
| 4800 | + for all supported frequency offsets. |
| 4801 | + on (str, default None): |
| 4802 | + For a DataFrame, column to use instead of index for resampling. Column |
| 4803 | + must be datetime-like. |
| 4804 | + level (str or int, default None): |
| 4805 | + For a MultiIndex, level (name or number) to use for resampling. |
| 4806 | + level must be datetime-like. |
| 4807 | + origin(str, default 'start_day'): |
| 4808 | + The timestamp on which to adjust the grouping. Must be one of the following: |
| 4809 | + 'epoch': origin is 1970-01-01 |
| 4810 | + 'start': origin is the first value of the timeseries |
| 4811 | + 'start_day': origin is the first day at midnight of the timeseries |
| 4812 | + Origin values 'end' and 'end_day' are *not* supported. |
| 4813 | + Returns: |
| 4814 | + DataFrameGroupBy: DataFrameGroupBy object. |
| 4815 | + """ |
| 4816 | + |
4737 | 4817 | def round(self, decimals): |
4738 | 4818 | """ |
4739 | 4819 | Round a DataFrame to a variable number of decimal places. |
|
0 commit comments