---
title: columns
description: "DataFrame.columns property in PySpark: Retrieves the names of all columns in the DataFrame as a list. The order of the column names in the list reflects their order in the DataFrame."
canonical_url: https://docs.databricks.com/aws/en/pyspark/reference/classes/dataframe/columns
---

# columns

Retrieves the names of all columns in the `DataFrame` as a list. The order of the column names in the list reflects their order in the DataFrame.

## Returns

`list`

## Examples

Retrieve column names of a DataFrame.

```python
df = spark.createDataFrame(
    [(14, "Tom", "CA"), (23, "Alice", "NY"), (16, "Bob", "TX")],
    ["age", "name", "state"]
)
df.columns
# ['age', 'name', 'state']
```

Use column names to project specific columns.

```python
selected_cols = [col for col in df.columns if col != "age"]
df.select(selected_cols).show()
# +-----+-----+
# | name|state|
# +-----+-----+
# |  Tom|   CA|
# |Alice|   NY|
# |  Bob|   TX|
# +-----+-----+
```

Check if a specific column exists in a DataFrame.

```python
"state" in df.columns
# True
"salary" in df.columns
# False
```
