Skip to content

How to Convert Pandas DataFrame to List?

Updated on

Converting a Pandas DataFrame to a Python list is a common task in data cleaning, exporting, feature engineering, and API data preparation. While tolist() is still widely used, Pandas has introduced more explicit and modern approaches—such as to_numpy() and to_dict()—that often provide better clarity and performance.

This updated guide covers:

  • Converting a DataFrame to a list of lists
  • Converting a single column to a list
  • Creating nested lists or tuples
  • Modern alternatives such as list of dicts (commonly used for JSON/API output)

⚡ Bonus: Visualize Your Data Instantly

Want to explore your DataFrame visually without writing plotting code?

PyGWalker is an open-source Python tool that turns your Pandas or Polars DataFrame into an interactive Tableau-like UI inside Jupyter Notebook.

Simply install and run:

pip install pygwalker
import pygwalker as pyg
gwalker = pyg.walk(df)
Run in Kaggle (opens in a new tab)Run in Google Colab (opens in a new tab)⭐ GitHub (opens in a new tab)

🧩 1. Convert an Entire DataFrame to a List (List of Lists)

The most common way is to convert each row into a list.

✔ Recommended (2025): df.to_numpy().tolist()

import pandas as pd
 
df = pd.DataFrame({'numbers': [1, 2, 3], 'letters': ['a', 'b', 'c']})
list_from_df = df.to_numpy().tolist()
print(list_from_df)

Output:

[[1, 'a'], [2, 'b'], [3, 'c']]

Why prefer to_numpy() over df.values?

  • df.values is older and may behave inconsistently with certain dtypes
  • to_numpy() is the modern, explicit method recommended by Pandas

🧩 2. Convert a Single Column to a List

Use Series.tolist() — fast and clean.

list_from_column = df["numbers"].tolist()
print(list_from_column)

Output:

[1, 2, 3]

🧩 3. Create Nested Lists or Tuples (List of Tuples)

If you need tuples (e.g., for SQL inserts or API inputs):

nested_list = [tuple(row) for row in df.to_numpy()]
print(nested_list)

Output:

[(1, 'a'), (2, 'b'), (3, 'c')]

Alternative using to_records():

nested_list = [tuple(x) for x in df.to_records(index=False)]

⭐ Bonus: Convert to List of Dicts (Best for JSON / APIs)

Many real-world applications expect JSON-like objects.

list_of_dicts = df.to_dict(orient="records")
print(list_of_dicts)

Output:

[
  {"numbers": 1, "letters": "a"},
  {"numbers": 2, "letters": "b"},
  {"numbers": 3, "letters": "c"}
]

This is the most common modern format for:

  • APIs
  • Machine learning feature export
  • Writing to JSON files
  • Passing structured data between systems

📌 Quick Examples (Summary)

# list of lists
df.to_numpy().tolist()
 
# using df.values (older)
df.values.tolist()
 
# column → list
df["numbers"].tolist()
 
# list of tuples
[tuple(x) for x in df.to_numpy()]
 
# list of dicts (JSON-ready)
df.to_dict("records")

✅ Conclusion

Converting a Pandas DataFrame to a list is simple, but choosing the right format depends on your use case:

GoalBest Method
Represent rows as listsdf.to_numpy().tolist()
Convert a single columndf[col].tolist()
Use tuples (SQL/API)[tuple(x) for x in df.to_numpy()]
Convert to JSON-ready objectsdf.to_dict("records")

With these modern techniques, you’ll be able to transform your DataFrame cleanly and efficiently—whether you're preparing data for modeling, visualization, or exporting.