# Make a list of the column headers in a Python Pandas DataFrame

**URL:** https://sentry.io/answers/make-a-list-of-the-column-headers-in-a-python-pandas-dataframe/

---

## The Problem

How can I create a list of the column headers in a Python Pandas DataFrame?

## The Solution

The simplest way to do this is by directly casting the DataFrame to a list:

```python
import pandas

data = {
    "A": [1, 2, 3],
    "B": [4, 5, 6],
    "C": [7, 8, 9]
}
df = pandas.DataFrame(data)
column_names = list(df)

print(column_names) # will print ['A', 'B', 'C']
```

A more explicit method is to use [`df.columns.tolist()`](https://pandas.pydata.org/docs/reference/api/pandas.Index.tolist.html):

```python
import pandas

data = {
    "A": [1, 2, 3],
    "B": [4, 5, 6],
    "C": [7, 8, 9]
}
df = pandas.DataFrame(data)

column_names = df.columns.tolist()

print(column_names) # will print ['A', 'B', 'C']
```

---

*Source: [sentry.io/answers/make-a-list-of-the-column-headers-in-a-python-pandas-dataframe/](https://sentry.io/answers/make-a-list-of-the-column-headers-in-a-python-pandas-dataframe/)*
