# Pandas: Select DataFrame Rows by Column Value

> Filter a Pandas DataFrame by column value using the loc property, with examples for equality, inequality, list membership, and numeric ranges

**URL:** https://sentry.io/answers/select-rows-from-a-python-pandas-dataframe-based-on-column-values/

---

## The Problem

How can I select rows from a DataFrame in Python Pandas based on column values? In other words, what is the DataFrame equivalent of a `SELECT WHERE` statement in SQL?

## The Solution

This can be achieved using the DataFrame's [`loc`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.loc.html#pandas.DataFrame.loc) property.

To select rows with a specified column value:

```python
my_value = 3
results = my_dataframe.loc[my_dataframe["column_name"] == my_value]
```

To select rows that do not match a specified column value:

```python
my_value = 3
results = my_dataframe.loc[my_dataframe["column_name"] != my_value]
```

To select rows with a column value that matches one of a list of values:

```python
my_list = [1, 2, 3]
results = my_dataframe.loc[my_dataframe["column_name"].isin(my_list)]
```

To select rows with a column value that falls in a range:

```python
lower_limit = 1
upper_limit = 3
my_dataframe.loc[(my_dataframe["column_name"] >= lower_limit) & (my_dataframe["column_name"] <= upper_limit)]
```

## Further Reading

If you're looking to get a deeper understanding of how Python application monitoring works, take a look at the following articles:

- [Logging in Python: A Developer's Guide](https://blog.sentry.io/logging-in-python-a-developers-guide/)
- [Application Performance Monitoring Explained](https://sentry.io/resources/application-performance-monitoring-explained/)
- [Python: Set Up Tracing](https://docs.sentry.io/platforms/python/tracing/)
- [Sentry for Python](https://docs.sentry.io/platforms/python/)
- [Python Error and Performance Monitoring](https://sentry.io/for/python/)
- [11 Habits of Highly Effective Developers](https://syntax.fm/show/778/11-habits-of-highly-effective-developers)

---

*Source: [sentry.io/answers/select-rows-from-a-python-pandas-dataframe-based-on-column-values/](https://sentry.io/answers/select-rows-from-a-python-pandas-dataframe-based-on-column-values/)*
