Skip to content
  • (+91) 9409548155
  • support@appdividend.com
  • Home
  • Pricing
  • Instructor
  • Tutorials
    • Laravel
    • Python
    • React
    • Javascript
    • Angular
  • Become A Tutor
  • About Us
  • Contact Us
Menu
  • Home
  • Pricing
  • Instructor
  • Tutorials
    • Laravel
    • Python
    • React
    • Javascript
    • Angular
  • Become A Tutor
  • About Us
  • Contact Us
  • Home
  • Pricing
  • Instructor
  • Tutorials
    • Laravel
    • Python
    • React
    • Javascript
    • Angular
  • Become A Tutor
  • About Us
  • Contact Us
Python

How to Convert Pandas DataFrame to Python List

  • 28 Oct, 2025
  • Com 2
How to Convert Pandas DataFrame to Python List

When it comes to converting a Pandas DataFrame to a Python List, it depends on what type of output you want. For example, you can convert a whole DataFrame to a List of Lists (Row-Wise, Preserves Order), a single column to a flat list, or a DataFrame to a list of dicts.

Converting a full DataFrame to a List

Converting a full DataFrame to a List in Python

The df.values.tolist() method converts the whole DataFrame into a list of lists, where each row becomes a list, and it keeps order (row-wise). This approach is fast and memory-efficient, but it loses column names.

import pandas as pd

df = pd.DataFrame({
    'A': [11, 21, 31],
    'B': ['x', 'y', 'z'],
    'C': [True, False, True]
})

print(df.values.tolist())

# Output: [[11, 'x', True], [21, 'y', False], [31, 'z', True]]

In the DataFrame df, we defined 3 columns, each containing three values.

The output list had three rows, each containing 3 values. The first row has [11, ‘x’, True]. The second row is [21, ‘y’, False]. The third row is [31, ‘z’, True].

Empty DataFrame

If the input DataFrame is empty, the output list will be empty too!

import pandas as pd

empty_df = pd.DataFrame()

empty_list = empty_df.values.tolist()

print(empty_list)

# Output: []

Converting a DataFrame column to a list

Converting a DataFrame column to a list

The df[‘col_name’].tolist() method selects by column label (name) and converts it to a list. This method is for a specific column. If you want a list of specific column values, you can use this approach.

import pandas as pd

df = pd.DataFrame({
    'A': [11, 21, 31],
    'B': ['x', 'y', 'z'],
    'C': [True, False, True]
})

list_B = df['B'].tolist()

print(list_B)

# Output: ['x', 'y', 'z']

In this code, I want to fetch the column “B”‘s values as a list, so we used df[‘B’] to select that column and converted all the values to a list using the tolist() method.

Converting a DataFrame to a List of dicts

Use the df.to_dict(‘records’) method when you want an output as a list of dictionaries. It is feasible for REST APIs, NoSQL, JSON dumps, and readable output.

The main advantage of this approach is that it retains column names as keys. However, it is slightly slower than a list of lists, as dictionaries use more memory.

import pandas as pd

df = pd.DataFrame({
    'A': [11, 21, 31],
    'B': ['x', 'y', 'z'],
    'C': [True, False, True]
})

list_of_dicts = df.to_dict('records')

print(list_of_dicts)

# Output: [{'A': 11, 'B': 'x', 'C': True}, {'A': 21, 'B': 'y', 'C': False}, {'A': 31, 'B': 'z', 'C': True}]

That’s all!

Post Views: 5
Share on:
Krunal Lathiya

With a career spanning over eight years in the field of Computer Science, Krunal’s expertise is rooted in a solid foundation of hands-on experience, complemented by a continuous pursuit of knowledge.

How to Convert a Python Dictionary to a NumPy Array
How to Convert Python Bytes to Numpy Array

2 Comments

  1. R A

    May 13, 2021 at 8:07 pm

    Thanks a lot Sir, you are genius

    Reply
  2. threadsGuy

    August 28, 2023 at 8:20 pm

    This is a great post! I was wondering how to do the same thing with my dataframe.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Address: TwinStar, South Block – 1202, 150 Ft Ring Road, Nr. Nana Mauva Circle, Rajkot(360005), Gujarat, India

Call: (+91) 9409548155

Email: support@appdividend.com

Online Platform

  • Pricing
  • Instructors
  • FAQ
  • Refund Policy
  • Support

Links

  • About Us
  • Contact Us
  • Privacy Policy
  • Terms of services

Tutorials

  • Angular
  • React
  • Python
  • Laravel
  • Javascript
Copyright @2024 AppDividend. All Rights Reserved
Appdividend