title_wip

[Edit this page](https://github.com/ClickHouse/clickhouse-docs/blob/main/docs/chdb/datastore/pandas-compat.md)

DataStore implements **209 pandas DataFrame methods** for full API compatibility. Your existing pandas code works with minimal changes.

## Compatibility Approach[​](#approach "Direct link to Compatibility Approach")

```
# Typical migration - just change the import
- import pandas as pd
+ from chdb import datastore as pd

# Your code works unchanged
df = pd.read_csv("data.csv")
result = df[df['age'] > 25].groupby('city')['salary'].mean()
```

**Key principles:**

- All 209 pandas DataFrame methods implemented
- Lazy evaluation for SQL optimization
- Automatic type wrapping (DataFrame → DataStore, Series → ColumnExpr)
- Immutable operations (no `inplace=True`)

---

## Attributes and Properties[​](#attributes "Direct link to Attributes and Properties")

|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| Property Description Triggers Execution|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | `shape` (rows, columns) tuple Yes|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | `columns` Column names (Index) Yes|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | `dtypes` Column data types Yes|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | `values` NumPy array Yes|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | `index` Row index Yes|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | `size` Number of elements Yes|  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | `ndim` Number of dimensions No|  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | | `empty` Is DataFrame empty Yes|  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | | `T` Transpose Yes|  |  |  | | --- | --- | --- | | `axes` List of axes Yes | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |

**Examples:**

```
from chdb import datastore as pd

ds = pd.read_csv("data.csv")

print(ds.shape)      # (1000, 5)
print(ds.columns)    # Index(['name', 'age', 'city', 'salary', 'dept'])
print(ds.dtypes)     # name: object, age: int64, ...
print(ds.empty)      # False
```

---

## Indexing and Selection[​](#indexing "Direct link to Indexing and Selection")

|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| Method Description Example|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | `df['col']` Select column `ds['age']`| `df[['col1', 'col2']]` Select columns `ds[['name', 'age']]`| `df[condition]` Boolean indexing `ds[ds['age'] > 25]`| `df.loc[...]` Label-based access `ds.loc[0:10, 'name']`| `df.iloc[...]` Integer-based access `ds.iloc[0:10, 0:3]`| `df.at[...]` Single value by label `ds.at[0, 'name']`| `df.iat[...]` Single value by position `ds.iat[0, 0]`| `df.head(n)` First n rows `ds.head(10)`| `df.tail(n)` Last n rows `ds.tail(10)`| `df.sample(n)` Random sample `ds.sample(100)`| `df.select_dtypes()` Select by Dtype `ds.select_dtypes(include='number')`| `df.query()` Query expression `ds.query('age > 25')`| `df.where()` Conditional replace `ds.where(ds['age'] > 0, 0)`| `df.mask()` Inverse where `ds.mask(ds['age'] < 0, 0)`| `df.isin()` Value membership `ds['city'].isin(['NYC', 'LA'])`| `df.get()` Safe column access `ds.get('col', default=None)`| `df.xs()` Cross-section `ds.xs('key')`| `df.pop()` Remove column `ds.pop('col')` | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |

---

## Statistical Methods[​](#statistical "Direct link to Statistical Methods")