Friday, September 5, 2025
HomeLanguagesGet a list of a particular column values of a Pandas DataFrame

Get a list of a particular column values of a Pandas DataFrame

In this article, we’ll see how to get all values of a column in a pandas dataframe in the form of a list. This can be very useful in many situations, suppose we have to get marks of all the students in a particular subject, get phone numbers of all employees, etc. Let’s see how we can achieve this with the help of some examples.

Example 1: We can have all values of a column in a list, by using the tolist() method.

Syntax: Series.tolist().

Return type: Converted series into List.

Python3




# import pandas libraey
import pandas as pd
 
# dictionary
dict = {'Name': ['Martha', 'Tim',
                'Rob', 'Georgia'],
         'Marks': [87, 91,
                  97, 95]}
 
# create a dataframe object
df = pd.DataFrame(dict)
 
# show the dataframe
print(df)
 
# list of values of 'Marks' column
marks_list = df['Marks'].tolist()
 
# show the list
print(marks_list)


Output:

dataframe

Example 2: We’ll see how we can get the values of all columns in separate lists.

Python3




# import pandas library
import pandas as pd
 
# dictionary
dict = {'Name': ['Martha', 'Tim',
                'Rob', 'Georgia'],
        'Marks': [87, 91,
                 97, 95]}
 
# create a dataframe object
df = pd.DataFrame(dict)
 
# show the dataframe
print(df)
 
# iterating over and calling
# tolist() method for
# each column
for i in list(df):
   
    # show the list of values 
    print(df[i].tolist())


Output:

dataframe with list of column values

RELATED ARTICLES

Most Popular

Dominic
32265 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6635 POSTS0 COMMENTS
Nicole Veronica
11801 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11864 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7026 POSTS0 COMMENTS
Thapelo Manthata
6703 POSTS0 COMMENTS
Umr Jansen
6719 POSTS0 COMMENTS