Select a single column of data as a Series in Pandas

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing pandas as library
import pandas as pd
  
# creating data frame:
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

chevron_right


Output:



select-singly-column-pandas-1

Step 2: Selecting Column using dataframe.column name:

filter_none

edit
close

play_arrow

link
brightness_4
code

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))

chevron_right


Output:

single-column-pandas-dataframe-2

Step 3: Selecting column using dataframe[column_name]

filter_none

edit
close

play_arrow

link
brightness_4
code

# using [] method
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))

chevron_right


Output:

select-single-column-pandas-3

In the above two examples we have used pd.Series() to select a single column of a data frame as a series.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.