QualityAssessments Methods
Source code in vee_qa/quality_assessments.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | |
boosted_function_qa(paid_df, organic_df, gsheet_name, tab_name='OrganicWithBigImpressions', impressions_threshold=100000)
Takes in organic data and paid data and reports how many are mislabelled as boosted
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
paid_df |
pandas.DataFrame
|
Daily ad spend, boosted posts identified in the 'workstream' column |
required |
organic_df |
pandas.DataFrame
|
Organic Post performance Data |
required |
impressions_threshold |
pandas.DataFrame
|
The number of impressions above which it is unlikely the post is purely organic |
100000
|
Returns:
| Name | Type | Description |
|---|---|---|
error_message |
str
|
A string detailing what the error is so that it can be passed to a notification service like slack |
Source code in vee_qa/quality_assessments.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | |
check_data_recency(df, cols_to_group, gsheet_name, tab_name='DataRecency', three_days_for_monday=True, date_col='date', dayfirst='EnterValue', yearfirst='EnterValue', format=None, errors='raise')
Post a google sheet showing how many days since different channels have been active. Also return a list of channels that have been inactive for more than 2 days which might be indicative of an error
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df |
pandas.DataFrame
|
Dataframe of data containing a 'date' column |
required |
cols_to_group |
list or str
|
Columns to groupby effectively creating the 'channels' |
required |
gsheet_name |
str
|
Name of the google sheet to write to |
required |
tab_name |
str
|
Name of the tab in the Google sheet |
'DataRecency'
|
three_days_for_monday |
bool
|
If the check is run on a Monday, give 3 days before declaring a channel as inactive because of the weekend. |
True
|
date_col |
str
|
Column name for the date to find the maximum value for based on grouping by |
'date'
|
dayfirst |
bool
|
If True, parses dates with the day first, eg 10/11/12 is parsed as 2012-11-10. If False, parses dates with the month first, eg 10/11/12 is parsed as 2010-11-12. If None, this is set to True if the day is in the first position in the format string, False otherwise. If dayfirst is set to True, parsing will be faster, but will fail for ambiguous dates, such as 01/02/03. |
'EnterValue'
|
yearfirst |
bool
|
If True parses dates with the year first, eg 10/11/12 is parsed as 2010-11-12. If both dayfirst and yearfirst are True, yearfirst is preceded (same as dateutil). If False, parses dates with the month first, eg 10/11/12 is parsed as 2012-11-10. If None, this defaults to False. Setting yearfirst to True is not recommended, as it can result in ambiguous dates. |
'EnterValue'
|
format |
str
|
Format to use for strptime. If None, the format is inferred from the first non-NaN element of the column. If the format is inferred, it will be used in subsequent parsing, even if the format changes. To specify a format string that will be used in parsing regardless of the inferred format, use pd.to_datetime with format. |
None
|
errors |
str
|
If 'raise', then invalid parsing will raise an exception. If 'coerce', then invalid parsing will be set as NaT. If 'ignore', then invalid parsing will return the input. |
'raise'
|
Returns:
| Name | Type | Description |
|---|---|---|
error_message |
str
|
String error message describing which channels are recently inactive. This message can then be sent to a slack function |
Source code in vee_qa/quality_assessments.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
check_impressions_no_engagements(df, gsheet_name, tab_name='NoImpressionsButEngagements', raise_exceptions=False)
Function to check if a row item has engagements but no impressions and no video views. This shouldn't happen and is indicative of an error with Tracer but can be valid as some platforms count viral engagements differently.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df |
DataFrame
|
Input dataframe of advertising data with columns 'impressions' or 'video_views' |
required |
gsheet_name |
str
|
name of the google sheet |
required |
tab_name |
str
|
name of the tab. Defaults to 'NoImpressionsButEngagements'. |
'NoImpressionsButEngagements'
|
raise_exceptions |
bool
|
Boolean flag if set to true will raise an exception if an offending row item is discovered. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
error_message |
str
|
String detailing what the error is so that it can be passed to a notification service like slack. |
Source code in vee_qa/quality_assessments.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | |
comparison_with_previous_data(df, name_of_df, cols_to_check=['impressions', 'likes'], perc_increase_threshold=20, perc_decrease_threshold=0.5, check_cols_set=True, raise_exceptions=False)
This function stores the high level sums for a datatable from the previous run of the script and if they have reduced or increased too sharply an error is raised.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df |
pd.DataFrame
|
Input dataframe that the historic checks are going to be performed on. |
required |
name_of_df |
str
|
Name of the dataframe, this will be used to name a file to save for future comparison. |
required |
cols_to_check |
List[str]
|
A list of strings that detail the columns to be totaled which will then be compared with previous data. |
['impressions', 'likes']
|
perc_increase_threshold |
float
|
A number between 0 and 100, the percentage increase threshold above which it is deemed that the totals have raised too rapidly and an error has occured. |
20
|
perc_decrease_threshold |
float
|
A number between 0 and 100, the percentage decrease threshold below which it is deemed that the totals decreased and an error has occured. |
0.5
|
check_cols_set |
bool
|
If true, store the set of columns present for comparison to see if any new columns have been added or removed next time, in which case it is deemed an error has occured. |
True
|
raise_exceptions |
bool
|
If true, then raise an exception if an error has occured instead of just returning an error message. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
error_message |
str
|
String detailing what the error is so that it can be passed to a notification service like slack. |
Source code in vee_qa/quality_assessments.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | |
duplicates_qa(df, df_name, subset=None, drop_duplicates=True)
Checks for duplicates and optionally drops duplicates in a dataframe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df |
pd.DataFrame
|
The Dataframe to be checked for duplicates |
required |
df_name |
str
|
The name of the dataframe to be used for logging purposes |
required |
subset |
Optional[Union[list, str]]
|
Only consider certain columns for identifying duplicates, by default use all of the columns |
None
|
drop_duplicates |
bool
|
If true remove duplicate values |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
df |
pd.DataFrame
|
Returns original dataframe without duplicates if 'drop_duplicates' = True |
Source code in vee_qa/quality_assessments.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | |
naming_convention_checker(df, gsheet_name, naming_convention, campaignname_dict=None, adgroupname_dict=None, adname_dict=None, campaign_col='campaign_name', adgroup_col='group_name', adname_col='name', start_char='_', middle_char=':', end_char='_')
Checks for naming convention errors in a given DataFrame and outputs the errors to a Google Sheet.
The function takes in a DataFrame containing paid data with columns for campaign name, ad group name, and ad name, as well as a DataFrame containing the accepted tags and values for each level of naming (campaign, ad group, ad name). Dictionarys for each level fo checking are required this specifies what tags should be checked for, e.g. should a check for the correct values in 'platform' be performed. If a dictionary for a certain level is not provided that level will not be checked. The function will output a table in a Google Sheet showing all errors in naming conventions, with a tab for each level of errors.
The Google Sheet should be set up with a tab name for each level of errors to check for, i.e. 'CampaignNameErrors', 'AdGroupNameErrors', 'AdNameErrors'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df |
DataFrame
|
The DataFrame containing paid data with campaign name, ad group name, and ad name columns. |
required |
naming_convention |
DataFrame
|
The DataFrame containing the accepted tags and values for each level of naming. |
required |
campaignname_dict |
dict
|
A dictionary of the tags to be checked for the campaign name, with the column label as the key and the shortcode as the value. |
None
|
adgroupname_dict |
dict
|
A dictionary of the tags to be checked for the ad group name, with the column label as the key and the shortcode as the value. |
None
|
adname_dict |
dict
|
A dictionary of the tags to be checked for the ad name, with the column label as the key and the shortcode as the value. |
None
|
campaign_col |
str
|
The column in the input DataFrame that corresponds to the campaign name. Defaults to 'campaign_name'. |
'campaign_name'
|
adgroup_col |
str
|
The column in the input DataFrame that corresponds to the ad group name. Defaults to 'group_name'. |
'group_name'
|
adname_col |
str
|
The column in the input DataFrame that corresponds to the ad name. Defaults to 'name'. |
'name'
|
start_char |
str
|
The starting character for the tag in the naming convention. Defaults to '_'. |
'_'
|
middle_char |
str
|
The character that separates the tag from the value in the naming convention. Defaults to ':'. |
':'
|
end_char |
str
|
The ending character for the tag in the naming convention. Defaults to '_'. |
'_'
|
Returns:
| Type | Description |
|---|---|
Writes to a Google Sheet a table with the index being a unique instance of the campaign. |
Source code in vee_qa/quality_assessments.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | |
null_values_checker(df, cols_to_group, cols_to_ignore, gsheet_name, tab_name, null_definitions=[np.nan, 'N/A', '', 'None'], output_method='gsheet')
Takes in a dataframe and columns to groupby and checks how many null values or null equivalents there are in the rest of the columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df |
pandas.DataFrame
|
The Input Dataframe of any type where you want to check for nulls. |
required |
cols_to_group |
list of str
|
The list of columns to perform a groupby operation with the null percentage counts will be a percentage of nulls in these groupbys. |
required |
cols_to_ignore |
list of str
|
The list of columns to not count nulls in, to make the output dataframe smaller perhaps. |
required |
gsheet_name |
str
|
The name of the google sheet workbook to pass to the google sheet function. |
required |
tab_name |
str
|
The name of the tab in the google sheet workbook to pass to the google sheet function. The google sheet must be setup with this tab already created. |
required |
null_definitions |
list
|
A list containing elements to be defined as a null value. |
[np.nan, 'N/A', '', 'None']
|
output_method |
str
|
A string identifying whether the output is to be sent to a Google sheet ('gsheet') or returned as a dataframe ('Dataframe'). |
'gsheet'
|
Returns:
| Name | Type | Description |
|---|---|---|
null_count_df |
pandas.DataFrame
|
Dataframe showing the percentage of nulls in each column grouped by the 'cols_to_group'. |
Source code in vee_qa/quality_assessments.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |