1. DataFrame.**`loc`**[...] → DataFrame
- The default API to use for selecting data in Pandas DataFrames.
1. DataFrame.**`query`**(expr, \*, inplace=False) → DataFrame
- A better API for moderate to complex Boolean queries.
1. DataFrame.**`xs`**(label, axis=0, level=None, drop_level=True) → Series | DataFrame
- To select at particular index or column levels, without specifying the path from the top level.
# loc API
### loc[label]
Get the row with index `label` as a **Series**, unless this is a MultiIndex.
Special cases of `label`:
- `(level1, level2, ...)` → a MultiIndex row (or frame, if only a prefix)
- `label1:label2` → a slice of rows
### loc[\[label, ...\]]
Get all rows the the specified labels as a **DataFrame**.
For example, `[('level1labelA', 'level2labelX'), ('level1labelB', 'level2labelY'), ...]` returns a slice of rows matching the listed multi-index rows as DataFrame.
### loc[label, column]
Get the value in the cell specified by the `label` and `column` as a value or **Series**.
If column is a list, return a **DataFrame**, instead.
### loc[conditional]
E.g., `df.loc[df['col1'] > 0]` → a **conditional** that generates a Boolean list for selecting rows returned as a Series.
Special cases:
- AND: `&`→ `df.loc[(df['col1'] > 1) & (df['col2'] < 8)]`
- OR: `|` → `df.loc[(df['col1'] > 4) | (df['col2'] < 5)]`
- Values from selected column only: `df.loc[df['col1'] > 0, ['col2']`
# query API
### label == 'value'
Query for simple Boolean expressions by naming the column:
```python
df.query("name == 'Florian'")
df.query("col1 > col2")
df.query("col1 > 0 and col2 < 0")
```
This mostly just follows standard Python syntax.
### @variable
With `@` you can even reference environment variables:
```python
items = ['Florian', 'Mayte']
df.query("name in @items")
```
### 'key' in index
You can refer to the `index` (explicitly) in a query or even to specific index level names in a MultiIndex.
### \`Col A\` > 1
Use backticks to quote names with spaces or characters beyond letters and the underscore.
### inplace=True
Modifies the DataFrame to only contain the selected rows rather than returning a new one.
# xs API
### label
Get the rows at the specified index `label` from the top level index.
### label, level=1
Get the rows at the specified index `label` and **at the specified index `level`**.
Level can itself be the column or index label, or a 1-based level number.
For example, `df.xs('target', level=2)` Selects all rows indexed with a second-level label 'target'.
### drop_level=False
Leaves the selected index `label` levels in the returned DataFrame.