I have the following dataframe:
import numpy as np
import pandas as pd
import random
df = pd.DataFrame(np.random.randint(0,20,size=(2, 2)), columns=list('AB'))
df
    A   B
0   13  4
1   16  17
Then I create another dataframe in a loop where the columns of the dataframe are lists. There is a post here (Pandas split column of lists into multiple columns) that shows to split the columns.
tmp_lst_1 = []
for index, row in df.iterrows():
    tmp_lst_2 = []
    for r in range(len(row)):
        tmp_lst_2.insert(r, random.sample(range(1, 50), 2) )
    tmp_lst_1.insert(index, tmp_lst_2)
df1 = pd.DataFrame(tmp_lst_1)
df1
     0             1
0   [21, 5]     [6, 42]
1   [49, 40]    [8, 45]
but I was wondering if there is a more efficient way to create this dataframe without needing to split all the columns individually? I am looking to get something like this:
df1
    C  D  E F  
0   21 5  6 42
1   49 40 8 45
 
    