0

I have 2 datasets.

dict1 =pd.DataFrame({'Name' : ['A','B','C','D'], 'Score' : [19,20,11,12]})
list1 =pd.DataFrame(['Math', 'English', 'History', 'Science'])
concat_data = pd.concat([dict1,list1])

output :

Name  Score        0
0    A   19.0      NaN
1    B   20.0      NaN
2    C   11.0      NaN
3    D   12.0      NaN
0  NaN    NaN     Math
1  NaN    NaN  English
2  NaN    NaN  History
3  NaN    NaN  Science

The output I am looking for:

Name  Score        0
0    A   19.0      Math
1    B   20.0      English
2    C   11.0      History
3    D   12.0      Science

Can anyone help me with this?

petezurich
  • 6,779
  • 8
  • 29
  • 46

1 Answers1

1

All you need to do is pass the correct axis. The default behavior for concat is axis=0 which means the operation takes place index-wise or row-wise, while you are needing the operation to be performed column-wise:

axis: {0/’index’, 1/’columns’}, default 0 The axis to concatenate along.

concat_data = pd.concat([dict1,list1],axis=1)
print(concat_data)

Outputs:

 Name  Score        0
0    A     19     Math
1    B     20  English
2    C     11  History
3    D     12  Science
Celius Stingher
  • 11,967
  • 4
  • 12
  • 37