How can I concatenate two Series and create one DataFrame ? For example, I have series like:
a=pd.Series([1,2,3])
b=pd.Series([4,5,6])
And, I want to get a data frame like:
pd.DataFrame([[1,4], [2,5], [3,6]])
Shortest would be:
pd.DataFrame([a,b]).T
Or:
pd.DataFrame(zip(a,b))
0 1
0 1 4
1 2 5
2 3 6
Or use concat
:
>>> pd.concat([a,b],axis=1)
0 1
0 1 4
1 2 5
2 3 6
>>>
Or join
:
>>> a.to_frame().join(b.to_frame(name=1))
0 1
0 1 4
1 2 5
2 3 6
>>>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With