1

This is hopefully a simple question, but I'm not too familiar with the different types of joins/merges.

I have a table that looks like this:

ice cream    code
chocolate    ZYX
vanilla      GRB
orange       YUK

I essentially want to add another column, or alternatively merge with another dataframe, so that the final result will alternate between the values from this column

Let's say the other dataframe I'm merging with is just a single column called bi_num with two rows: 0 and 1

The final result should be:

ice cream    code   bi_num
chocolate    ZYX    0
chocolate    ZYX    1
vanilla      GRB    0
vanilla      GRB    1
orange       YUK    0
orange       YUK    1
JesusMonroe
  • 1,421
  • 3
  • 13
  • 20

1 Answers1

0

You can use merge:

from pandas import merge
df1['key'] = 1
df2['key'] = 1
result = merge(df1, df2, on='key')[['ice cream', 'code', 'bi_num']]

where df1, df2 - your data frames.

Lev Zakharov
  • 2,409
  • 1
  • 10
  • 24