merge_dataframes

typhoon.test.capture.merge_dataframes(left, right, interpolation_method='time', rename_repeated=False)

Merge two DataFrame objects with a database-style join. This function is wrapper around pandas.DataFrame.merge and pandas.DataFrame.resample functions: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.merge.html and https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.resample.html. Join is done on indexes of DataFrames, which should both be pandas.Timedelta. The ‘right’ DataFrame is merged to the left by using outer join style to preserve all the data for interpolation, which comes consequently. After that, dataframe is resampled with time between first two samples of the left dataframe used as sample time. If left dataframe has syncronous data (and it is good practice to put synchronous dataframe as left), the resulting dataframe would have the same indices as the left. First valid value is used to replace all NaN values before it.

Parameters:
  • left (pandas.DataFrame) – DataFrame object used on the left side of the join operation

  • right (pandas.DataFrame) – DataFrame object used on the right side of the join operation

  • interpolation_method ({'time', 'pad'}, default 'time') –

    Method to replace NaN values after the first valid value. Available methods:

    • ’time’: same argument from pandas.DataFrame.interpolate: link
      It can be viewed as piece-wise linear interpolation based on pandas.Timedelta index of the DataFrame: Gap is filled by doing linear interpolation between the previous and the next valid value.
    • ’pad’: This method is using existing values to fill in NaNs.
      The last valid observation is used to fill the gap.

  • rename_repeated (bool, default False) –

    • False: If ‘left’ and ‘right’ DataFrames have any columns with the same name, a NameError Exception is raised.

    • True: If ‘left’ and ‘right’ DataFrames have any columns with the same name, they are renamed.
      It is attached ‘_x’ and ‘_y’ to the end of their names, respectively.

Returns:

Merged DataFrame object with signals from both input DataFrames

Return type:

pandas.DataFrame

Examples