fusetools.analytics_tools.Pandas¶
-
class
fusetools.analytics_tools.Pandas[source]¶ Bases:
objectFunctions for running analytical Pandas operations
Methods
Joins a window function’s aggregation to a Pandas DataFrame.
Returns the combination of 2 de-duped columns in a Pandas DataFrame.
Creates a snapshot comparison between two periods.
Returns the first day of a year or month for a Pandas Series.
Creates a ‘Period to date’ aggregation.
Computes a YoY cumulative YTD comparison across for a given week.
-
classmethod
append_window_agg(df, dim, metric, metric_agg, comp_col=False)[source]¶ Joins a window function’s aggregation to a Pandas DataFrame.
- Parameters
df – Pandas DataFrame.
dim – Column for which to partition of data by.
metric – Column to aggregate.
metric_agg – Type of calculation to perform.
comp_col – Flag of whether or not to create a comparison column.
- Returns
Pandas DataFrame with a window function’s aggregation.
-
classmethod
find_na_holder(df, col, col_new)[source]¶ Returns the combination of 2 de-duped columns in a Pandas DataFrame.
- Parameters
df – Pandas DataFrame
col – Original column.
col_new – New column.
- Returns
Combination of 2 de-duped columns in a Pandas DataFrame.
-
classmethod
period_comp(df, period_field, val_fields, dim=False, val_field_suffix=False, hist=False)[source]¶ Creates a snapshot comparison between two periods.
- Parameters
df – Pandas DataFrame.
period_field – Column with period to compare across
val_fields – List of columns with numeric values to compare
dim – Column with dimension to group across (optional)
val_field_suffix – Suffix for value field to add to final dataset (optional)
hist – Include history flag, returns all periods if True, otherwise just the most recent two periods
- Returns
Comparison Pandas DataFrame
-
classmethod
period_start_dt(df)[source]¶ Returns the first day of a year or month for a Pandas Series.
- Parameters
df – Pandas DataFrame.
- Returns
First day of year or month for Pandas Series.
-
classmethod
ptd_measure(df, period, val_fields, kpi, dim=False)[source]¶ Creates a ‘Period to date’ aggregation.
- Parameters
df – Pandas DataFrame
period – Type of period (year, month)
val_fields – Columns to aggregate.
kpi – Type of aggregation to perform.
dim – Dimension to group comparison by (Optional).
- Returns
Pandas DataFrame with PTD measure.
-
classmethod
yoy_comp(df, val_dict, dim=False, hist=False)[source]¶ Computes a YoY cumulative YTD comparison across for a given week.
- Parameters
df – Pandas DataFrame.
val_dict – Column and aggregation type specification.
dim – Dimension to group comparison by (Option).
hist – Flag of whether to keep all historical date combinations.
- Returns
Pandas DataFrame with YoY cumulative YTD comparison.
-
classmethod