python - DataFrames repeat combination -


i have dataframe df1 , df2:

df1 = pd.dataframe(['a1','a2'])      0 0  a1 1  a2 df2 = pd.dataframe(pd.date_range('2016-01-01',periods = 2, freq = '1d'))            0 0 2016-01-01 1 2016-01-02 

how gonna dataframe?

    0    1 0  a1  2016-01-01 1  a1  2016-01-02 2  a2  2016-01-01 3  a2  2016-01-02 

you can use itertools:

import itertools  pd.dataframe(list(it.product(df1[0], df2[0])))     0          1 0  a1 2016-01-01 1  a1 2016-01-02 2  a2 2016-01-01 3  a2 2016-01-02 

itertools returns generator, need convert list before converting dataframe

it.product makes combinations between 2 iterables objects, eg.:

["".join(i) in it.product("abc", "abc")] ['aa', 'ab', 'ac', 'ba', 'bb', 'bc', 'ca', 'cb', 'cc'] 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -