module mlhelper.joins

Short summary

module pyensae.mlhelper.joins

Complex joins with pandas.

source on GitHub

Functions

function

truncated documentation

df_crossjoin

Make a cross join (cartesian product) between two dataframes by using a constant temporary key. Also sets a MultiIndex …

Documentation

Complex joins with pandas.

source on GitHub

pyensae.mlhelper.joins.df_crossjoin(df1, df2, **kwargs)

Make a cross join (cartesian product) between two dataframes by using a constant temporary key. Also sets a MultiIndex which is the cartesian product of the indices of the input dataframes. Source: `Cross join / cartesian product between pandas DataFrames https://mkonrad.net/2016/04/16/cross-join--cartesian-product-between-pandas-dataframes.html>`_.

Parameters:
  • df1 – dataframe 1

  • df2 – dataframe 2

  • kwargs – keyword arguments that will be passed to pd.merge()

Returns:

cross join of df1 and df2

Cross join with a pandas dataframe

<<<

import pandas
from pyensae.mlhelper import df_crossjoin
df = pandas.DataFrame([{"x": 3, "y": 4}, {"x": 5, "y": 6}])
jj = df_crossjoin(df, df.copy())

>>>

    

A dataframe cannot be joined on itself, the second one musrt be copied.

source on GitHub