eta_nexus.timeseries.dataframes module
Simple helpers for reading timeseries data from a csv file and getting slices or resampled data. This module handles data using pandas dataframe objects.
- eta_nexus.timeseries.dataframes.find_time_slice(time_begin: datetime, time_end: datetime | None = None, total_time: TimeStep | None = None, round_to_interval: TimeStep | None = None, *, random: bool | np.random.Generator = False) tuple[datetime, datetime][source]
Return a (potentially random) slicing interval that can be used to slice a data frame.
- Parameters:
time_begin – Date and time of the beginning of the interval to slice from.
time_end – Date and time of the ending of the interval to slice from.
total_time – Specify the total time of the sliced interval. An integer will be interpreted as seconds. If this argument is None, the complete interval between beginning and end will be returned.
round_to_interval – Round times to a specified interval, this value is interpreted as seconds if given as an int. Default is no rounding.
random – If this value is true, or a random generator is supplied, it will be used to generate a random slice of length total_time in the interval between time_begin and time_end.
- Returns:
Tuple of slice_begin time and slice_end time. Both times are datetime objects.
- eta_nexus.timeseries.dataframes.df_time_slice(df: pd.DataFrame, time_begin: datetime, time_end: datetime | None = None, total_time: TimeStep | None = None, round_to_interval: TimeStep | None = None, *, random: bool | np.random.Generator = False) pd.DataFrame[source]
Return a data frame which has been sliced starting at time_begin and ending at time_end, from df.
- Parameters:
df – Original data frame to be sliced.
time_begin – Date and time of the beginning of the interval to slice from.
time_end – Date and time of the ending of the interval to slice from.
total_time – Specify the total time of the sliced interval. An integer will be interpreted as seconds. If this argument is None, the complete interval between beginning and end will be returned.
round_to_interval – Round times to a specified interval, this value is interpreted as seconds if given as an int. Default is no rounding.
random – If this value is true, or a random generator is supplied, it will be used to generate a random slice of length total_time in the interval between time_begin and time_end.
- Returns:
Sliced data frame.
- eta_nexus.timeseries.dataframes.df_resample(dataframe: pd.DataFrame, *periods_deltas: TimeStep, missing_data: FillMethod | None = None) pd.DataFrame[source]
Resample the time index of a data frame. This method can be used for resampling in multiple different periods with multiple different deltas between single time entries.
- Parameters:
df – DataFrame for processing.
periods_deltas – If one argument is specified, this will resample the data to the specified interval in seconds. If more than one argument is specified, they will be interpreted as (periods, interval) pairs. The first argument specifies a number of periods that should be resampled, the second value specifies the interval that these periods should be resampled to. A third argument would determine the next number of periods that should be resampled to the interval specified by the fourth argument and so on.
missing_data – Specify a method for handling missing data values. If this is not specified, missing data will not be handled. Valid methods are: ‘ffill’, ‘bfill’, ‘interpolate’, ‘asfreq’. Default is ‘asfreq’.
- Returns:
Resampled copy of the DataFrame.
- eta_nexus.timeseries.dataframes.df_interpolate(dataframe: pd.DataFrame, freq: TimeStep, limit_direction: Literal['both', 'forward', 'backward'] = 'both') pd.DataFrame[source]
Interpolate missing values in a DataFrame with a specified frequency. Is able to handle unevenly spaced time series data.
- Parameters:
dataframe – DataFrame for interpolation.
freq – Frequency of the resulting DataFrame.
limit_direction – Direction in which to limit the interpolation. Defaults to “both”.
- Returns:
Interpolated DataFrame.