Source: https://databento.com/docs/api-historical/helpers/dbn-store-to-df


### DBNStore.to\_df

Converts data to a [pandas](https://pandas.pydata.org/) DataFrame.

> **Info**
>
> The DataFrame index will be set to `ts_recv` if it exists in the schema, otherwise it will be set to `ts_event`.

> **See also**
>
> While not optimized for use with live data due to their column-oriented format,
> pandas DataFrames can still be used with live data by first streaming DBN data to a file,
> then converting to a DataFrame with DBNStore.from_file().to_df().
> See [this example](https://databento.com/docs/examples/basics-live/live-stream-to-file.md) for more information.

#### API method

```python
DBNStore.to_df(
    price_type: PriceType | str = "float",
    pretty_ts: bool = True,
    map_symbols: bool = True,
    schema: Schema | str | None = None,
    tz: datetime.tzinfo | str = zoneinfo.ZoneInfo("UTC"),
    count: int | None = None,
) -> pd.DataFrame | DataFrameIterator
```

#### Parameters

| Parameter | Type | Required | Description |
| `price_type` | PriceType or str, default "float" | optional | The price type to use for price fields. If "fixed", prices will have a type of `int` in fixed decimal format; each unit representing 1e-9 or 0.000000001. If "float", prices will have a type of `float`. If "decimal", prices will be instances of `decimal.Decimal`. |
| `pretty_ts` | bool, default True | optional | Whether timestamp columns are converted to tz-aware `pandas.Timestamp`. The timezone can be specified using the `tz` parameter. |
| `map_symbols` | bool, default True | optional | If symbology mappings from the metadata should be used to create a 'symbol' column, mapping the instrument ID to its raw symbol for every record. |
| `schema` | Schema or str | optional | The data record [schema](https://databento.com/docs/schemas/whats-a-schema.md) for the output DataFrame. Must be one of the values from [list\_schemas](https://databento.com/docs/api-historical/metadata/metadata-list-schemas.md). This is only required when reading a `DBNStore` with mixed record types. |
| `tz` | datetime.tzinfo or str, default UTC | optional | If `pretty_ts` is `True`, all timestamps will be converted to the specified timezone. |
| `count` | int | optional | If set, instead of returning a single `DataFrame` a `DataFrameIterator` instance will be returned. When iterated, this object will yield a `DataFrame` with at most `count` elements until the entire contents of the `DBNStore` are exhausted. |

#### Returns

A pandas [DataFrame](https://pandas.pydata.org/docs/reference/frame.html) object.

#### Example usage

```python
import databento as db

client = db.Historical("$YOUR_API_KEY")

data = client.timeseries.get_range(
    dataset="GLBX.MDP3",
    schema="trades",
    symbols=["ESM2"],
    start="2022-03-06",
)

df = data.to_df()
print(df.head())
```
#### Example response

```plaintext
                                                               ts_event  rtype  publisher_id  instrument_id action  ... size  flags  ts_in_delta  sequence  symbol
ts_recv                                                                                                             ...
2022-03-06 23:00:00.039463300+00:00 2022-03-06 23:00:00.036436177+00:00      0             1           3403      T  ...    1      0        18828      5178    ESM2
2022-03-06 23:00:01.098111252+00:00 2022-03-06 23:00:01.097477845+00:00      0             1           3403      T  ...    1      0        19122      6816    ESM2
2022-03-06 23:00:04.612334175+00:00 2022-03-06 23:00:04.611714663+00:00      0             1           3403      T  ...    1      0        18687     10038    ESM2
2022-03-06 23:00:04.613776789+00:00 2022-03-06 23:00:04.613240435+00:00      0             1           3403      T  ...    1      0        18452     10045    ESM2
2022-03-06 23:00:06.881864467+00:00 2022-03-06 23:00:06.880575603+00:00      0             1           3403      T  ...    1      0        18478     11343    ESM2

[5 rows x 13 columns]
```
