This quick tutorial will cover the topic of writing a DataFrame column to a Python list.
Consider the following code snippet:
# import the pandas package
import pandas as pd
# initialize the DataFrame
data = pd.DataFrame({ "manager": ["Debbie", "Daisy", "Dorothy", "Tim"] * 2,
"target": [32000, 45000, 18000, 20000] * 2})
data.head()
Here’s our DataFrame header:
| manager | target | |
|---|---|---|
| 0 | Debbie | 32000 |
| 1 | Daisy | 45000 |
| 2 | Dorothy | 18000 |
| 3 | Tim | 20000 |
| 4 | Debbie | 32000 |
Using pd.DataFrame.tolist() to write column to a list
Here’s the Python code you’ll need to export column values to a Python list:
# Dataframe Column values to Python list
data['manager'].values.tolist()
Here’s the list object we’ll get:
[‘Debbie’, ‘Daisy’, ‘Dorothy’, ‘Tim’, ‘Debbie’, ‘Daisy’, ‘Dorothy’, ‘Tim’]
Pandas column index to list
data['manager'].index.tolist()
[0, 1, 2, 3, 4, 5, 6, 7]
Unique column values to list
As shown above, we were able to export the values to a list. The list however had duplicated entries. Here’s how to ensure that the list has only unique values:
# Export unique column values only
data['manager'].unique().tolist()
[‘Debbie’, ‘Daisy’, ‘Dorothy’, ‘Tim’]
Unique list values using set
Other way to ensure uniqueness in the list is to convert it to a set to get rid of duplicated values.
unique_managers = set(data['manager'].values.tolist())
list(unique_managers)
tolist() with condition
What if we just want to write values that satisfy a condition?
# Condition: Only managers which name starts with the letter D
cond = data['manager'].str.startswith('D')
data[cond]['manager'].unique().tolist()
Here’s the result:
[‘Debbie’, ‘Daisy’, ‘Dorothy’]
Series values to List
For completeness, here’s a short snippet for writing Series values to a list (you can find a more complete example here)
manager_series = pd.Series(["Debbie", "Kim", "Dorothy", "Tim"])
manager_series.to_list()
Going Further
Can I export a DataFrame index to a list the same way as a column?
The approach is nearly identical. Use df.index.tolist() to convert the index into a standard Python list. This works for default integer indices, named indices, and DatetimeIndex objects alike. If your DataFrame uses a MultiIndex, tolist() returns a list of tuples representing each level combination. For a deeper walkthrough of index conversion scenarios, including exporting to NumPy arrays, see the guide on converting a Pandas index to a list or array. The method is consistent across Pandas versions and handles missing index values gracefully by preserving NaN entries in the output list.
How do I export only unique column values or filter rows before converting?
Chain .unique().tolist() on a column to extract deduplicated values — for example, df['city'].unique().tolist() returns distinct city names in order of first appearance. For conditional exports, apply a boolean mask first: df[df['sales'] > 100]['product'].tolist() gives you product names only where sales exceed 100. When filtering by specific row values across multiple conditions, techniques for finding DataFrame rows by value pair well with tolist() to build precise, filtered lists from your data.
What is the performance difference between tolist() and list() on a DataFrame column?
Both df['col'].tolist() and list(df['col']) produce identical output, but tolist() is faster for large DataFrames because it operates directly on the underlying NumPy array without Python-level iteration. On a column with one million rows, tolist() typically runs two to three times faster. The difference becomes negligible below ten thousand rows. Also note that tolist() converts NumPy data types to native Python types automatically, which matters when serializing to JSON or passing values to libraries that reject NumPy scalars.