DataCollection objects, how to convert them into DataFrames, and how to export them to files.
DataCollection
Every method onCoinMetricsClient returns a DataCollection. A DataCollection is a lazy wrapper around the underlying request: it captures the endpoint and parameters, but it does not hit the API until you iterate over it or call a transformation method (to_list(), to_dataframe(), export_to_csv(), …).
By default, time-series methods stream their response (format='json_stream'), so a single iteration over a DataCollection typically fetches everything in one continuous response. For example, to get market trades for the Coinbase BTC-USD pair:
Exploring Available Data
Use thecatalog_*_v2 methods to discover what data is available. For example, to list markets that report trades data:
catalog-v2 endpoints are designed to feed the historical-data endpoints. For example, to fetch one hour of all BTC market trades from Coinbase:
DataFrames
Pandas
DataCollection.to_dataframe() materializes the response as a pandas DataFrame:
dtype_mapper:
Polars
Polars is a high-performance DataFrame library and a more performant alternative to pandas in many cases. Passdataframe_type="polars" to to_dataframe():
LazyFrames
DataFrames eagerly load data into memory. Lazy execution defers materialization, which is useful when you want to apply intermediate transformations to large datasets before collecting. Convert aDataCollection into a polars LazyFrame with to_lazyframe(). See the Best Practices guide for an in-depth example.
Data Exports
You can stream aDataCollection directly to a CSV, JSON, or Parquet file using export_to_csv(), export_to_json(), and export_to_parquet():
parallel().export_to_csv_files(), parallel().export_to_json_files(), and parallel().export_to_parquet_files() to write one file per worker.
