imsciences 0.9.5.1__py3-none-any.whl → 0.9.5.3__py3-none-any.whl

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.

imsciences/geo.py CHANGED
@@ -199,13 +199,13 @@ class geoprocessing:
199
199
 
200
200
  return analysis_df
201
201
 
202
- def process_city_analysis(self, raw_input_path, spend_input_path, output_path, group1, group2, response_column):
202
+ def process_city_analysis(self, raw_data, spend_data, output_path, group1, group2, response_column):
203
203
  """
204
204
  Process city analysis by grouping data, analyzing user metrics, and merging with spend data.
205
205
 
206
206
  Parameters:
207
- raw_input_path (str): Path to the raw input data file (CSV or XLSX) containing at least 'date', 'city', and the specified response column.
208
- spend_input_path (str): Path to the media spend data file (CSV or XLSX) with 'date', 'geo', and 'cost' columns. Costs should be numeric.
207
+ raw_data (str or pd.DataFrame): Raw input data as a file path (CSV/XLSX) or DataFrame.
208
+ spend_data (str or pd.DataFrame): Spend data as a file path (CSV/XLSX) or DataFrame.
209
209
  output_path (str): Path to save the final output file (CSV or XLSX).
210
210
  group1 (list): List of city regions for group 1.
211
211
  group2 (list): List of city regions for group 2.
@@ -217,13 +217,15 @@ class geoprocessing:
217
217
  import pandas as pd
218
218
  import os
219
219
 
220
- def read_file(file_path):
221
- """Helper function to read CSV or XLSX files."""
222
- ext = os.path.splitext(file_path)[1].lower()
220
+ def read_file(data):
221
+ """Helper function to handle file paths or return DataFrame directly."""
222
+ if isinstance(data, pd.DataFrame):
223
+ return data
224
+ ext = os.path.splitext(data)[1].lower()
223
225
  if ext == '.csv':
224
- return pd.read_csv(file_path)
226
+ return pd.read_csv(data)
225
227
  elif ext in ['.xlsx', '.xls']:
226
- return pd.read_excel(file_path)
228
+ return pd.read_excel(data)
227
229
  else:
228
230
  raise ValueError("Unsupported file type. Please use a CSV or XLSX file.")
229
231
 
@@ -237,9 +239,9 @@ class geoprocessing:
237
239
  else:
238
240
  raise ValueError("Unsupported file type. Please use a CSV or XLSX file.")
239
241
 
240
- # Read input files
241
- raw_df = read_file(raw_input_path)
242
- spend_df = read_file(spend_input_path)
242
+ # Read data
243
+ raw_df = read_file(raw_data)
244
+ spend_df = read_file(spend_data)
243
245
 
244
246
  # Ensure necessary columns are present
245
247
  required_columns = {'date', 'city', response_column}
imsciences/mmm.py CHANGED
@@ -492,15 +492,15 @@ class dataprocessing:
492
492
 
493
493
  return combined_df
494
494
 
495
- def pivot_table(self, df, index_col, columns, values_col, filters_dict=None, fill_value=0, aggfunc="sum", margins=False, margins_name="Total", datetime_trans_needed=True, date_format="%Y-%m-%d", reverse_header_order=False, fill_missing_weekly_dates=False, week_commencing="W-MON"):
495
+ def pivot_table(self, df, index_col, columns, values_col, filters_dict=None, fill_value=0, aggfunc="sum", margins=False, margins_name="Total", datetime_trans_needed=True, date_format="%Y-%m-%d", reverse_header_order=False, fill_missing_weekly_dates=True, week_commencing="W-MON"):
496
496
  """
497
497
  Provides the ability to create pivot tables, filtering the data to get to data you want and then pivoting on certain columns
498
498
 
499
499
  Args:
500
500
  df (pandas.DataFrame): The DataFrame containing the data.
501
501
  index_col (str): Name of Column for your pivot table to index on
502
- columns (str): Name of Columns for your pivot table.
503
- values_col (str): Name of Values Columns for your pivot table.
502
+ columns (str or list): Name of Column(s) for your pivot table. Can be a single column or a list of columns.
503
+ values_col (str or list): Name of Values Column(s) for your pivot table. Can be a single column or a list of columns.
504
504
  filters_dict (dict, optional): Dictionary of conditions for the boolean mask i.e. what to filter your df on to get to your chosen cell. Defaults to None
505
505
  fill_value (int, optional): The value to replace nan with. Defaults to 0.
506
506
  aggfunc (str, optional): The method on which to aggregate the values column. Defaults to sum.
@@ -514,14 +514,19 @@ class dataprocessing:
514
514
  Returns:
515
515
  pandas.DataFrame: The pivot table specified
516
516
  """
517
-
518
517
  # Validate inputs
519
518
  if index_col not in df.columns:
520
519
  raise ValueError(f"index_col '{index_col}' not found in DataFrame.")
521
- if columns not in df.columns:
522
- raise ValueError(f"columns '{columns}' not found in DataFrame.")
523
- if values_col not in df.columns:
524
- raise ValueError(f"values_col '{values_col}' not found in DataFrame.")
520
+
521
+ columns = [columns] if isinstance(columns, str) else columns
522
+ for col in columns:
523
+ if col not in df.columns:
524
+ raise ValueError(f"columns '{col}' not found in DataFrame.")
525
+
526
+ values_col = [values_col] if isinstance(values_col, str) else values_col
527
+ for col in values_col:
528
+ if col not in df.columns:
529
+ raise ValueError(f"values_col '{col}' not found in DataFrame.")
525
530
 
526
531
  # Apply filters if provided
527
532
  if filters_dict:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: imsciences
3
- Version: 0.9.5.1
3
+ Version: 0.9.5.3
4
4
  Summary: IMS Data Processing Package
5
5
  Author: IMS
6
6
  Author-email: cam@im-sciences.com
@@ -5,8 +5,8 @@ imsciences/__init__.py,sha256=_HuYeLbDMTdt7GpKI4r6-d7yRPZgcAQ7yOW0-ydR2Yo,117
5
5
  imsciences/datafunctions-IMS-24Ltp-3.py,sha256=3Snv-0iE_03StmyjtT-riOU9f4v8TaJWLoyZLJp6l8Y,141406
6
6
  imsciences/datafunctions.py,sha256=WZrXNLO-SYrCuFt0pAbha74psMOZPY7meWJ7yWEbRpk,169953
7
7
  imsciences/datapull.py,sha256=TPY0LDgOkcKTBk8OekbD0Grg5x0SomAK2dZ7MuT6X1E,19000
8
- imsciences/geo.py,sha256=kBFc4_DEyQDQlnGnCc09qcydoaW5Lium6kTSdz3li3c,13526
9
- imsciences/mmm.py,sha256=M91Qs_ijtY4EytTo1rruWCOVGnV7DMVaYUhNpP1NVNc,73920
8
+ imsciences/geo.py,sha256=J8AkLk1Nyty3VBkPFqcseXjtlSvXVNkHW_nymERz3nA,13472
9
+ imsciences/mmm.py,sha256=W7e46fw0c2V9n_-fU3O6F0X1P5tbC2dkMrqnDLJH28g,74230
10
10
  imsciences/pull.py,sha256=bGz8B7bBQ5b9hrx3ipCFTWl_eebEb7rPL4dANKiVWTY,74015
11
11
  imsciences/unittesting.py,sha256=DYGqVCsZHrs_tZ-EXDW8q8CdlcsTnG8HsnmWjEE521c,45691
12
12
  imsciences/vis.py,sha256=2izdHQhmWEReerRqIxhY4Ai10VjL7xoUqyWyZC7-2XI,8931
@@ -14,9 +14,9 @@ imsciencesdataprocessing/__init__.py,sha256=quSwsLs6IuLoA5Rzi0ZD40xZaQudwDteF7_a
14
14
  imsciencesdataprocessing/datafunctions.py,sha256=vE1vsZ8xOSbR9Bwlp9SWXwEHXQ0nFydwGkvzHXf2f1Y,41
15
15
  imsdataprocessing/__init__.py,sha256=quSwsLs6IuLoA5Rzi0ZD40xZaQudwDteF7_ai9JfTPk,32
16
16
  imsdataprocessing/datafunctions.py,sha256=vE1vsZ8xOSbR9Bwlp9SWXwEHXQ0nFydwGkvzHXf2f1Y,41
17
- imsciences-0.9.5.1.dist-info/LICENSE.txt,sha256=lVq2QwcExPX4Kl2DHeEkRrikuItcDB1Pr7yF7FQ8_z8,1108
18
- imsciences-0.9.5.1.dist-info/METADATA,sha256=aTHbZ8Hr_JNbE_UQwbP5CSJtPM-BHNmHnRUn9wlbQXE,16994
19
- imsciences-0.9.5.1.dist-info/PKG-INFO-IMS-24Ltp-3,sha256=yqZbigwHjnYoqyI81PGz_AeofRFfOrwH_Vyawyef-mg,854
20
- imsciences-0.9.5.1.dist-info/WHEEL,sha256=ixB2d4u7mugx_bCBycvM9OzZ5yD7NmPXFRtKlORZS2Y,91
21
- imsciences-0.9.5.1.dist-info/top_level.txt,sha256=hsENS-AlDVRh8tQJ6-426iUQlla9bPcGc0-UlFF0_iU,11
22
- imsciences-0.9.5.1.dist-info/RECORD,,
17
+ imsciences-0.9.5.3.dist-info/LICENSE.txt,sha256=lVq2QwcExPX4Kl2DHeEkRrikuItcDB1Pr7yF7FQ8_z8,1108
18
+ imsciences-0.9.5.3.dist-info/METADATA,sha256=J6mScUPG8way2ZfnDauRvqqKDUSriU3dZ1POLQuJmno,16994
19
+ imsciences-0.9.5.3.dist-info/PKG-INFO-IMS-24Ltp-3,sha256=yqZbigwHjnYoqyI81PGz_AeofRFfOrwH_Vyawyef-mg,854
20
+ imsciences-0.9.5.3.dist-info/WHEEL,sha256=ixB2d4u7mugx_bCBycvM9OzZ5yD7NmPXFRtKlORZS2Y,91
21
+ imsciences-0.9.5.3.dist-info/top_level.txt,sha256=hsENS-AlDVRh8tQJ6-426iUQlla9bPcGc0-UlFF0_iU,11
22
+ imsciences-0.9.5.3.dist-info/RECORD,,