Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

cartesian product pandas

# In recent versions of Pandas (>= 1.2) this is built into merge so you can do:
from pandas import DataFrame
df1 = DataFrame({'col1':[1,2],'col2':[3,4]})
df2 = DataFrame({'col3':[5,6]})    

df1.merge(df2, how='cross')
Comment

pandas cartesian product

a = [1, 2, 3]
b = ["a", "b", "c"]

index = pd.MultiIndex.from_product([a, b], names = ["a", "b"])

pd.DataFrame(index = index).reset_index()
Comment

PREVIOUS NEXT
Code Example
Python :: cross join pandas 
Python :: simple graph in matplotlib categorical variables 
Python :: python find largest variable 
Python :: django timezone settings 
Python :: how to execute bash commands in python script 
Python :: python one line if statement no else 
Python :: python named group regex example 
Python :: ValueError: Found array with dim 3. Estimator expected <= 2. 
Python :: multiple boxplots python 
Python :: pandas drop if present 
Python :: django regexvalidator example 
Python :: python how to count items in array 
Python :: python aes encryption 
Python :: python substring in string 
Python :: scikit learn pca 
Python :: apply a created function pandas 
Python :: numpy random in python 
Python :: suppress python 
Python :: int to ascii python 
Python :: how to add item to a list python 
Python :: exclude last value of an array python 
Python :: Remove empty strings from the list of strings 
Python :: django in conda 
Python :: build a pile of cubes python 
Python :: python slack 
Python :: matplotlib display graph on jupyter notebook 
Python :: django tempalte tag datetime to timestamp 
Python :: Reading JSON from a File with Python 
Python :: subtract current date from pandas date column 
Python :: get name of month python 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =