In this article, we will discuss how to select a single column of data as a Series in Pandas.
For example, Suppose we have a data frame :
Name Age MotherTongue
Akash 21 Hindi
Ashish 23 Marathi
Diksha 21 Bhojpuri
Radhika 20 Nepali
Ayush 21 Punjabi
Now when we select column Mother Tongue as a Series we get the following output:
Hindi Marathi Bhojpuri Nepali Punjabi
Now let us try to implement this using Python:
Step1: Creating data frame:
import pandas as pd
df = pd.DataFrame({ 'name' : [ 'Akash' , 'Ayush' , 'Ashish' ,
'Diksha' , 'Shivani' ],
'Age' : [ 21 , 25 , 23 , 22 , 18 ],
'MotherTongue' : [ 'Hindi' , 'English' , 'Marathi' ,
'Bhojpuri' , 'Oriya' ]})
print ( "The original data frame" )
df
|
Output:

Step 2: Selecting Column using dataframe.column name:
print ( "Selecting Single column value using dataframe.column name" )
series_one = pd.Series(df.Age)
print (series_one)
print ( "Type of selected one" )
print ( type (series_one))
|
Output:

Step 3: Selecting column using dataframe[column_name]
print ( "Selecting Single column value using dataframe[column name]" )
series_one = pd.Series(df[ 'Age' ])
print (series_one)
print ( "Type of selected one" )
print ( type (series_one))
|
Output:

In the above two examples we have used pd.Series() to select a single column of a data frame as a series.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
01 Oct, 2020
Like Article
Save Article