brightwind.transform.transform.offset_timestamps

brightwind.transform.transform.offset_timestamps(data, offset, date_from=None, date_to=None, overwrite=False)

Offset timestamps by a certain time period

Parameters
  • data (pandas.DateTimeIndex, pandas.Series, pandas.DataFrame) – DateTimeIndex or Series/DataFrame with DateTimeIndex

  • offset (str) –

    A string specifying the time to offset the time-series.

    • Set offset to 10min to add 10 minutes to each timestamp, -10min to subtract 10 minutes and so on

      for 4min, 20min, etc.

    • Set offset to 1H to add 1 hour to each timestamp and -1H to subtract and so on for 5H, 6H, etc.

    • Set offset to 1D to add a day and -1D to subtract and so on for 5D, 7D, 15D, etc.

    • Set offset to 1W to add a week and -1W to subtract from each timestamp and so on for 2W, 4W, etc.

    • Set offset to 1M to add a month and -1M to subtract a month from each timestamp and so on for 2M, 3M, etc.

    • Set offset to 1Y to add an year and -1Y to subtract an year from each timestamp and so on for 2Y, 3Y, etc.

  • date_from (str, datetime, dict) – (Optional) The timestamp from input data where to start offsetting from.

  • date_to (str, datetime, dict) – (Optional) The timestamp from input data where to end offsetting.

  • overwrite (bool) – Change to True to overwrite the unadjusted timestamps if they are same outside of the slice of data you want to offset. False by default.

Returns

Offsetted DateTimeIndex/Series/DataFrame, same format is input data

Example usage

import brightwind as bw
data = bw.load_campbell_scientific(bw.datasets.demo_site_data)

#To decrease 10 minutes within a given date range and overwrite the original data
op1 = bw.offset_timestamps(data, offset='1H', date_from='2016-01-01 00:20:00',
    date_to='2016-01-01 01:40:00', overwrite=True)

#To decrease 10 minutes within a given date range not overwriting the original data
op2 = bw.offset_timestamps(data, offset='-10min', date_from='2016-01-01 00:20:00',
    date_to='2016-01-01 01:40:00')

#Can accept Series or index as input
op3 = bw.offset_timestamps(data.Spd80mS, offset='1D', date_from='2016-01-01 00:20:00')

op4 = bw.offset_timestamps(data.index, offset='-10min', date_from='2016-01-01 00:20:00',
    date_from='2016-01-01 01:40:00')

#Can also except decimal values for offset, like 3.5H for 3 hours and 30 minutes

op5 = bw.offset_timestamps(data.index, offset='3.5H', date_from='2016-01-01 00:20:00',
    date_from='2016-01-01 01:40:00')