reports#
- class analytix.reports.ColumnType(value)#
An enumeration of possible column types.
- DIMENSION = 'DIMENSION'#
- METRIC = 'METRIC'#
- class analytix.reports.DataType(value)#
An enumeration of possible data types.
- STRING = 'STRING'#
- INTEGER = 'INTEGER'#
- FLOAT = 'FLOAT'#
- class analytix.reports.ColumnHeader(name: str, column_type: ColumnType, data_type: DataType)#
A dataclass representing a column header.
- Parameters
name – The column name.
column_type – The column type.
data_type – The column’s data type.
- classmethod from_json(header: dict[str, str]) ColumnHeader #
Create a column header from its JSON representation.
- Parameters
header – The JSON representation of the column header.
- Returns
The newly created
ColumnHeader
instance.
- class analytix.reports.Report(data: dict[t.Any, t.Any], type: ReportType)#
A class representing a YouTube Analytics API report. You will never need to manually create an instance of this.
- Parameters
data – The raw data retrieved from the API.
type – The report type.
- data#
The raw data retrieved from the API.
- type#
The report type.
- property column_headers: list[ColumnHeader]#
The column headers in the report.
New in version 3.5.0.
- property columns: list[str]#
The names of all columns in the report.
Changed in version 3.5.0: This is now a property.
- property dimensions: set[str]#
The names of columns which are dimensions in the report.
New in version 3.3.0.
- property metrics: set[str]#
The names of columns which are metrics in the report.
New in version 3.3.0.
- property ordered_dimensions: list[str]#
The names of columns which are dimensions in the report in the order in which they appear.
New in version 3.5.0.
- property ordered_metrics: list[str]#
The names of columns which are metrics in the report in the order in which they appear.
New in version 3.5.0.
- to_dataframe(*, skip_date_conversion: bool = False) pd.DataFrame #
Export the report data to a pandas or Modin DataFrame. If you wish to use Modin, you are responsible for selecting and initialising your desired engine.
- Keyword Arguments
skip_date_conversion – Whether to skip automatically converting date columns to the
datetime64[ns]
format. Defaults toFalse
.- Returns
The newly created DataFrame.
- to_arrow_table(*, skip_date_conversion: bool = False) pa.Table #
Export the report data to an Apache Arrow Table.
- Keyword Arguments
skip_date_conversion – Whether to skip automatically converting date columns to the
timestamp[us]
format. Defaults toFalse
.- Returns
The newly constructed Apache Arrow Table.
New in version 3.2.0.
- to_json(path: str, *, indent: int = 4) JSONReportWriter #
Write the report data to a JSON file.
Note
This method can also be run asynchronously by awaiting it.
- Parameters
path – The path the file should be saved to.
- Keyword Arguments
indent – The amount of indentation the data should be written with. Defaults to
4
.- Returns
The report writer. This is done to allow this method to run sync or async in a typed context.
- to_csv(path: str, *, delimiter: str = ',') CSVReportWriter #
Write the report data to a CSV file.
Note
This method can also be run asynchronously by awaiting it.
- Parameters
path – The path the file should be saved to.
- Keyword Arguments
delimiter – The delimiter to use. Defaults to a comma. Passing a tab here will save the file as a TSV instead.
- Returns
The report writer. This is done to allow this method to run sync or async in a typed context.
- to_excel(path: str, *, sheet_name: str = 'Analytics') None #
Write the report data to an Excel spreadsheet.
- Parameters
path – The path the file should be saved to.
- Keyword Arguments
sheet_name – The name for the worksheet.
New in version 3.1.0.