imsciences 0.9.4__tar.gz → 0.9.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of imsciences might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: imsciences
3
- Version: 0.9.4
3
+ Version: 0.9.5
4
4
  Summary: IMS Data Processing Package
5
5
  Author: IMS
6
6
  Author-email: cam@im-sciences.com
@@ -236,6 +236,11 @@ Table of Contents
236
236
  - **Usage**: `process_itv_analysis(self, raw_df, itv_path, cities_path, media_spend_path, output_path, group1, group2)`
237
237
  - **Example**: `process_itv_analysis(df, 'itv regional mapping.csv', 'Geo_Mappings_with_Coordinates.xlsx', 'IMS.xlsx', 'itv_for_test_analysis_itvx.csv', ['West', 'Westcountry', 'Tyne Tees'], ['Central Scotland', 'North Scotland'])`
238
238
 
239
+ ## 3. `process_city_analysis`
240
+ - **Description**: Processes city-level data for geo experiments by grouping user metrics, merging with media spend data, and saving the result.
241
+ - **Usage**: `process_city_analysis(raw_df, spend_df, output_path, group1, group2, response_column)`
242
+ - **Example**: `process_city_analysis(df, spend, output, ['Barnsley'], ['Aberdeen'], 'newUsers')`
243
+
239
244
  ---
240
245
 
241
246
  ## Data Visualisations
@@ -211,6 +211,11 @@ Table of Contents
211
211
  - **Usage**: `process_itv_analysis(self, raw_df, itv_path, cities_path, media_spend_path, output_path, group1, group2)`
212
212
  - **Example**: `process_itv_analysis(df, 'itv regional mapping.csv', 'Geo_Mappings_with_Coordinates.xlsx', 'IMS.xlsx', 'itv_for_test_analysis_itvx.csv', ['West', 'Westcountry', 'Tyne Tees'], ['Central Scotland', 'North Scotland'])`
213
213
 
214
+ ## 3. `process_city_analysis`
215
+ - **Description**: Processes city-level data for geo experiments by grouping user metrics, merging with media spend data, and saving the result.
216
+ - **Usage**: `process_city_analysis(raw_df, spend_df, output_path, group1, group2, response_column)`
217
+ - **Example**: `process_city_analysis(df, spend, output, ['Barnsley'], ['Aberdeen'], 'newUsers')`
218
+
214
219
  ---
215
220
 
216
221
  ## Data Visualisations
@@ -30,6 +30,11 @@ class geoprocessing:
30
30
  print(" - Usage: process_itv_analysis(self, raw_df, itv_path, cities_path, media_spend_path, output_path, group1, group2)")
31
31
  print(" - Example:process_itv_analysis(df,'itv regional mapping.csv', 'Geo_Mappings_with_Coordinates.xlsx', 'IMS.xlsx', 'itv_for_test_analysis_itvx.csv', ['West', 'Westcountry', 'Tyne Tees'], ['Central Scotland', 'North Scotland'])")
32
32
 
33
+ print("\n3. process_city_analysis")
34
+ print(" - Description: Processes city-level data for geo experiments by grouping user metrics, merging with media spend data, and saving the result.")
35
+ print(" - Usage: process_city_analysis(raw_df, spend_df, output_path, group1, group2, response_column)")
36
+ print(" - Example:process_city_analysis(df, spend, output, ['Barnsley'], ['Aberdeen'], 'newUsers')")
37
+
33
38
  def pull_ga(self, credentials_file, property_id, start_date, country, metrics):
34
39
  """
35
40
  Pulls Google Analytics data using the BetaAnalyticsDataClient.
@@ -192,4 +197,54 @@ class geoprocessing:
192
197
  # Save the final output
193
198
  analysis_df.to_csv(output_path, index=False)
194
199
 
195
- return analysis_df
200
+ return analysis_df
201
+
202
+ def process_city_analysis(self, raw_df, spend_df, output_path, group1, group2, response_column):
203
+ """
204
+ Process city analysis by grouping data, analyzing user metrics, and merging with spend data.
205
+
206
+ Parameters:
207
+ raw_df (pd.DataFrame): Raw input data containing at least 'date' and 'city' columns, along with the specified response column.
208
+ spend_df (pd.DataFrame): DataFrame containing media spend data with 'date', 'geo', and 'cost' columns. Costs should be numeric.
209
+ output_path (str): Path to save the final output CSV file.
210
+ group1 (list): List of city regions for group 1.
211
+ group2 (list): List of city regions for group 2.
212
+ response_column (str): Column name to be used as the response metric.
213
+
214
+ Returns:
215
+ pd.DataFrame: Processed DataFrame.
216
+ """
217
+ import pandas as pd
218
+
219
+ # Ensure necessary columns are present
220
+ required_columns = {'date', 'city', response_column}
221
+ if not required_columns.issubset(raw_df.columns):
222
+ raise ValueError(f"Input DataFrame must contain the following columns: {required_columns}")
223
+
224
+ spend_required_columns = {'date', 'geo', 'cost'}
225
+ if not spend_required_columns.issubset(spend_df.columns):
226
+ raise ValueError(f"Spend DataFrame must contain the following columns: {spend_required_columns}")
227
+
228
+ # Convert cost column to numeric after stripping currency symbols and commas
229
+ spend_df['cost'] = spend_df['cost'].replace('[^\d.]', '', regex=True).astype(float)
230
+
231
+ # Rename and process input DataFrame
232
+ raw_df = raw_df.rename(columns={'city': 'geo', response_column: 'response'})
233
+
234
+ # Filter and group data
235
+ filtered_df = raw_df[raw_df['geo'].isin(group1 + group2)].copy()
236
+
237
+ grouped_df = filtered_df.groupby(['date', 'geo'], as_index=False).agg({'response': 'sum'})
238
+
239
+ assignment_map = {city: 1 for city in group1}
240
+ assignment_map.update({city: 2 for city in group2})
241
+ grouped_df['assignment'] = grouped_df['geo'].map(assignment_map)
242
+
243
+ # Merge with spend data
244
+ merged_df = pd.merge(grouped_df, spend_df, on=['date', 'geo'], how='left')
245
+ merged_df['cost'] = merged_df['cost'].fillna(0)
246
+
247
+ # Save the final output
248
+ merged_df.to_csv(output_path, index=False)
249
+
250
+ return merged_df
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: imsciences
3
- Version: 0.9.4
3
+ Version: 0.9.5
4
4
  Summary: IMS Data Processing Package
5
5
  Author: IMS
6
6
  Author-email: cam@im-sciences.com
@@ -236,6 +236,11 @@ Table of Contents
236
236
  - **Usage**: `process_itv_analysis(self, raw_df, itv_path, cities_path, media_spend_path, output_path, group1, group2)`
237
237
  - **Example**: `process_itv_analysis(df, 'itv regional mapping.csv', 'Geo_Mappings_with_Coordinates.xlsx', 'IMS.xlsx', 'itv_for_test_analysis_itvx.csv', ['West', 'Westcountry', 'Tyne Tees'], ['Central Scotland', 'North Scotland'])`
238
238
 
239
+ ## 3. `process_city_analysis`
240
+ - **Description**: Processes city-level data for geo experiments by grouping user metrics, merging with media spend data, and saving the result.
241
+ - **Usage**: `process_city_analysis(raw_df, spend_df, output_path, group1, group2, response_column)`
242
+ - **Example**: `process_city_analysis(df, spend, output, ['Barnsley'], ['Aberdeen'], 'newUsers')`
243
+
239
244
  ---
240
245
 
241
246
  ## Data Visualisations
@@ -8,7 +8,7 @@ def read_md(file_name):
8
8
  return f.read()
9
9
  return ''
10
10
 
11
- VERSION = '0.9.4'
11
+ VERSION = '0.9.5'
12
12
  DESCRIPTION = 'IMS Data Processing Package'
13
13
  LONG_DESCRIPTION = read_md('README.md')
14
14
 
File without changes
File without changes
File without changes
File without changes