Created
May 28, 2020 15:56
-
-
Save GermanCM/389abaec105d582519a92a03aeb14f9b to your computer and use it in GitHub Desktop.
Get all possible combinations from a dataset based on defined columns, as an n-dimensional cartesian product
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def makeCartesianProduct(array_x, array_y, array_z): | |
import pandas as pd | |
import itertools | |
return pd.DataFrame.from_records(itertools.product(array_x.reshape(-1, ), array_y.reshape(-1, ), array_z.reshape(-1, )), | |
columns=['x', 'y', 'z']) | |
combinations_cartesian_prod = makeCartesianProduct(jobs_df.A.unique(), jobs_df.B.unique(), jobs_df.C.unique()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment