def _preprocess_timeseries()

in src/lookoutequipment/plot.py [0:0]


    def _preprocess_timeseries(self, df):
        """
        Preprocess the timeseries to add a timestamp index and resample the
        data for the tag dataframe passed as an argument
        
        Parameters:
            df (pandas.DataFrame):
                The dataframe that contains the tag data to preprocess
        """
        if self.timestamp_col is not None:
            # Convert the timestamp to a proper format (without timezone) and
            # use it as an index:
            df[self.timestamp_col] = pd.to_datetime(df[self.timestamp_col])
            df[self.timestamp_col] = df[self.timestamp_col].dt.tz_localize(None)
            df = df.set_index(self.timestamp_col)

        # Resample the data if this was requested at initialization:
        if self.resample is not None:
            df = df.resample(self.resample).mean()
            df = df.fillna(method='ffill')
            
        return df