process_fivetran_ad_reporting#
- pymc_marketing.data.fivetran.process_fivetran_ad_reporting(df, value_columns='impressions', *, date_col='date_day', platform_col='platform', agg='sum', fill_value=0.0, include_missing_dates=False, freq='D', rename_date_to='date')[source]#
Process Fivetran Ad Reporting tables into wide, model-ready features.
Compatible with Fivetran’s Ad Reporting schema tables:
ad_reporting__account_report: daily metrics by account
ad_reporting__campaign_report: daily metrics by campaign and account
ad_reporting__ad_group_report: daily metrics by ad group, campaign and account
ad_reporting__ad_report: daily metrics by ad, ad group, campaign and account
The input data must include a date column, a platform column (e.g., vendor name), and one or more metric columns such as
spendorimpressions. The output is a wide dataframe with one row per date and columns named{platform}_{metric}.This function supports multiple DataFrame backends including pandas, polars, and PySpark. The output type will match the input type (type preservation).
- Parameters:
df (
IntoFrameT) – Input dataframe in long format with at least the date, platform, and metric columns. Accepts pandas.DataFrame, polars.DataFrame, polars.LazyFrame, or pyspark.DataFrame.value_columns (
str|Sequence[str]) – Column name(s) to aggregate and pivot. Example: “spend” or [“spend”, “impressions”].date_col (
str) – Name of the date column.platform_col (
str) – Name of the platform (vendor) column. Each distinct value becomes one channel. Pivoting on platform puts brand and non-brand search in a single channel; they usually belong in separate channels, so derive a channel column (for example fromcampaign_name) and pass it here.agg (
str) – Aggregation method applied during groupby. Supported: ‘sum’, ‘mean’, ‘min’, ‘max’, ‘count’.fill_value (
float|None) – Value used to fill missing values in the wide output. IfNone, missing values are left as NaN.include_missing_dates (
bool) – IfTrue, include a continuous date range and fill missing dates usingfill_value.freq (
str) – Frequency used wheninclude_missing_datesisTrue.rename_date_to (
str|None) – If provided, rename the date column in the result to this value. IfNone, keepdate_col.
- Return type:
DataFrame-like
- Returns:
A wide-format dataframe with one row per date and columns for each
{platform}_{metric}combination. The return type matches the input type.
Notes
Backend-specific implementation notes:
PySpark: Uses native PySpark pivot operations for distributed computing. This is a temporary workaround until narwhals adds LazyFrame.pivot support. See: narwhals-dev/narwhals#1901
pandas/polars: Uses narwhals pivot operations (works on eager DataFrames).
polars.LazyFrame: Input LazyFrames are automatically collected to eager DataFrames for the pivot operation, then results are returned as eager DataFrames.