

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Combining two Series into a DataFrame in Pandas
To combine two series into a DataFrame in Pandas, we can take two series and concatenate them using concat() method.
Steps
Create series 1 with two elements, where index is ['a', 'b'] and name is Series 1.
Print Series 1.
Make Series 2 with two elements, where index is ['a', 'b'] and name is Series 2.
Print Series 2.
Concatenate Pandas objects along a particular axis with optional set logic along the other axes.
Print the resultant DataFrame.
Example
import pandas as pd s1 = pd.Series([4, 16], index=['a', 'b'], name='Series 1') print "Input series 1 is: \n", s1 s2 = pd.Series([3, 9], index=['a', 'b'], name='Series 2') print "Input series 2 is: \n", s2 df = pd.concat([s1, s2], axis=1) print "Resultant DataFrame is:\n", df
Output
Input series 1 is: a 4 b 16 Name: Series 1, dtype: int64 Input series 2 is: a 3 b 9 Name: Series 2, dtype: int64 Resultant DataFrame is: Series 1 Series 2 a 4 3 b 16 9
- Related Questions & Answers
- How to convert a DataFrame into a dictionary in Pandas?
- Write a Python code to concatenate two Pandas series into a single series without repeating the index
- Python – Merge two Pandas DataFrame
- Correlation between two numeric columns in a Pandas DataFrame
- Combining two arrays in JavaScript
- Combining two heatmaps in seaborn
- Combining two sorted lists in Python
- How to Merge multiple CSV Files into a single Pandas dataframe ?
- Python - Convert list of nested dictionary into Pandas Dataframe
- Combining multiple images into a single one using JavaScript
- Python - How to group DataFrame rows into list in Pandas?
- Python Pandas – Filter DataFrame between two dates
- Combining multiple rows into a comma delimited list in MySQL?
- Python program to compare two Pandas series
- How to read a JSON file into a DataFrame using Python Pandas library?
Advertisements