> ## Documentation Index
> Fetch the complete documentation index at: https://knowledge.cloudquant.com/llms.txt
> Use this file to discover all available pages before exploring further.

# SuperQuery

> Resample pandas DataFrames from CloudQuant Data Liberator into a common time axis by querying multiple datasets simultaneously.

# SuperQuery

SuperQuery enables you to resample pandas DataFrames from CloudQuant Data Liberator into a common time axis by querying multiple datasets simultaneously.

## Initial setup

```python theme={null}
import liberator

symbols = ['TSLA']

as_of = '2024-06-07'

back_to = '2024-06-04'

%time df1 = liberator.get_dataframe(
    liberator.query(
        symbols=symbols,
        name='minute_bars',
        as_of=as_of,
        back_to=back_to
    )
)

liberator.get_dataframe(
    liberator.query(
        name='daily_bars',
        symbols=symbols,
        as_of=as_of,
        back_to=back_to
    )
)
```

This loads two independent datasets: minute bars and daily bars.

## Querying multiple datasets together

SuperQuery lets you specify how multiple datasets are reindexed and merged together using the `superq_resample_rule` parameter.

### Daily (1D) resampling

For a three-day query using daily frequency, the result contains three rows with daily bars and the final minute bar of each day:

```python theme={null}
df = liberator.get_dataframe(
    liberator.query(
        symbols=symbols,
        name=['daily_bars', 'minute_bars'],
        as_of=as_of,
        back_to=back_to,
        superq_periods_per_batch_override=5,
        superq_resample_rule='1D'
    )
)

df
```

### Hourly (60T) resampling

For a three-day query using 60-minute frequency, the result contains 24 rows per day. Daily bar data is timestamped at 8pm:

```python theme={null}
%time df4 = liberator.get_dataframe(
    liberator.query(
        symbols=symbols,
        name=['daily_bars', 'minute_bars'],
        as_of=as_of,
        back_to=back_to,
        superq_periods_per_batch_override=5,
        superq_resample_rule='60T'
    )
)

df
```

## The superq\_resample\_rule parameter

The `superq_resample_rule` parameter uses pandas "Offset Aliases" to define the resampling frequency.

Common values:

| Rule  | Frequency  |
| ----- | ---------- |
| `1T`  | 1 minute   |
| `5T`  | 5 minutes  |
| `15T` | 15 minutes |
| `60T` | 60 minutes |
| `1D`  | 1 day      |

<Info>
  For a complete list of offset aliases, see the [pandas time series offset aliases documentation](https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases).
</Info>
