Given the below DataFrame,
df = pd.DataFrame({'Student':['Siri','Alexa'], 'Class':['6', '7'], 'Section':['A','B'], 'Teacher':['Ravi','Mark'], 'School':['C','D']})
I would like to return a table with all possible combinations of the values of all columns. I achieved this, using the below code
df['key'] = 1
df1 = pd.merge(df.loc[:, ['key','Student']], df.loc[:,['key','Class']], how='outer')
df2 = df1.merge(df.loc[:,['key','Section']], how='outer')
df3 = df2.merge(df.loc[:,['key','Teacher']], how='outer')
df4 = df3.merge(df.loc[:,['key','School']], how='outer')
df4.drop(columns='key', inplace=True)
What is the simplest way to get this done, as I have 15 columns and through the above method, it would result in 14 merges and inefficient code?