1

I have two dataframes below. I need to add a column to a dataframe from another dataframe.

DataFrame 1:

index   A       
 0      UK
 1      RSA
 2      US

DataFrame 2 :

index  B
 0     UK 
 1     CF
 2     AT

I need output like below.

index   A    B
  0     UK   UK
  0     UK   CF
  0     UK   AT
  1     RSA  UK
  1     RSA  CF
  1     RSA  AT
  2     US   UK
  2     US   CF
  2     US   AT

I tried merge, concat, and join, but it didn't workout. Please help me on this.

SoConfused
  • 1,799
  • 3
  • 12
  • 18
  • @jdehesa , if this is the duplicate question , hw do i get the key column for my question from the answer which is there in the duplicate one , and this is just an example and i have 100 customers in my excel file who has different values for each customer – jimmy karan Jan 15 '19 at 15:09
  • Try with `df1 = pd.DataFrame({'A': ['UK', 'RSA', 'US']}); df2 = pd.DataFrame({'B': ['UK', 'CF', 'AT']}); df1['key'] = 1; df2['key'] = 1; result = pd.merge(df1, df2).drop('key', 1)` – jdehesa Jan 15 '19 at 15:47

0 Answers0