Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
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
Add a comment
Or use concat:
concat
>>> pd.concat([a,b],axis=1) 0 1 0 1 4 1 2 5 2 3 6 >>>
Or join:
join
>>> a.to_frame().join(b.to_frame(name=1)) 0 1 0 1 4 1 2 5 2 3 6 >>>
Another possible faster solution could be,
pd.DataFrame(np.vstack((a,b)).T)
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.