imsciences 0.9.5__py3-none-any.whl → 0.9.5.2__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.
- imsciences/geo.py +33 -6
- {imsciences-0.9.5.dist-info → imsciences-0.9.5.2.dist-info}/METADATA +1 -1
- {imsciences-0.9.5.dist-info → imsciences-0.9.5.2.dist-info}/RECORD +7 -7
- {imsciences-0.9.5.dist-info → imsciences-0.9.5.2.dist-info}/LICENSE.txt +0 -0
- {imsciences-0.9.5.dist-info → imsciences-0.9.5.2.dist-info}/PKG-INFO-IMS-24Ltp-3 +0 -0
- {imsciences-0.9.5.dist-info → imsciences-0.9.5.2.dist-info}/WHEEL +0 -0
- {imsciences-0.9.5.dist-info → imsciences-0.9.5.2.dist-info}/top_level.txt +0 -0
imsciences/geo.py
CHANGED
|
@@ -199,14 +199,14 @@ class geoprocessing:
|
|
|
199
199
|
|
|
200
200
|
return analysis_df
|
|
201
201
|
|
|
202
|
-
def process_city_analysis(self,
|
|
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
|
-
|
|
208
|
-
|
|
209
|
-
output_path (str): Path to save the final output CSV
|
|
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
|
+
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.
|
|
212
212
|
response_column (str): Column name to be used as the response metric.
|
|
@@ -215,6 +215,33 @@ class geoprocessing:
|
|
|
215
215
|
pd.DataFrame: Processed DataFrame.
|
|
216
216
|
"""
|
|
217
217
|
import pandas as pd
|
|
218
|
+
import os
|
|
219
|
+
|
|
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()
|
|
225
|
+
if ext == '.csv':
|
|
226
|
+
return pd.read_csv(data)
|
|
227
|
+
elif ext in ['.xlsx', '.xls']:
|
|
228
|
+
return pd.read_excel(data)
|
|
229
|
+
else:
|
|
230
|
+
raise ValueError("Unsupported file type. Please use a CSV or XLSX file.")
|
|
231
|
+
|
|
232
|
+
def write_file(df, file_path):
|
|
233
|
+
"""Helper function to write DataFrame to CSV or XLSX files."""
|
|
234
|
+
ext = os.path.splitext(file_path)[1].lower()
|
|
235
|
+
if ext == '.csv':
|
|
236
|
+
df.to_csv(file_path, index=False)
|
|
237
|
+
elif ext in ['.xlsx', '.xls']:
|
|
238
|
+
df.to_excel(file_path, index=False, engine='openpyxl')
|
|
239
|
+
else:
|
|
240
|
+
raise ValueError("Unsupported file type. Please use a CSV or XLSX file.")
|
|
241
|
+
|
|
242
|
+
# Read data
|
|
243
|
+
raw_df = read_file(raw_data)
|
|
244
|
+
spend_df = read_file(spend_data)
|
|
218
245
|
|
|
219
246
|
# Ensure necessary columns are present
|
|
220
247
|
required_columns = {'date', 'city', response_column}
|
|
@@ -245,6 +272,6 @@ class geoprocessing:
|
|
|
245
272
|
merged_df['cost'] = merged_df['cost'].fillna(0)
|
|
246
273
|
|
|
247
274
|
# Save the final output
|
|
248
|
-
merged_df
|
|
275
|
+
write_file(merged_df, output_path)
|
|
249
276
|
|
|
250
|
-
return merged_df
|
|
277
|
+
return merged_df
|
|
@@ -5,7 +5,7 @@ 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=
|
|
8
|
+
imsciences/geo.py,sha256=J8AkLk1Nyty3VBkPFqcseXjtlSvXVNkHW_nymERz3nA,13472
|
|
9
9
|
imsciences/mmm.py,sha256=M91Qs_ijtY4EytTo1rruWCOVGnV7DMVaYUhNpP1NVNc,73920
|
|
10
10
|
imsciences/pull.py,sha256=bGz8B7bBQ5b9hrx3ipCFTWl_eebEb7rPL4dANKiVWTY,74015
|
|
11
11
|
imsciences/unittesting.py,sha256=DYGqVCsZHrs_tZ-EXDW8q8CdlcsTnG8HsnmWjEE521c,45691
|
|
@@ -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.dist-info/LICENSE.txt,sha256=lVq2QwcExPX4Kl2DHeEkRrikuItcDB1Pr7yF7FQ8_z8,1108
|
|
18
|
-
imsciences-0.9.5.dist-info/METADATA,sha256=
|
|
19
|
-
imsciences-0.9.5.dist-info/PKG-INFO-IMS-24Ltp-3,sha256=yqZbigwHjnYoqyI81PGz_AeofRFfOrwH_Vyawyef-mg,854
|
|
20
|
-
imsciences-0.9.5.dist-info/WHEEL,sha256=ixB2d4u7mugx_bCBycvM9OzZ5yD7NmPXFRtKlORZS2Y,91
|
|
21
|
-
imsciences-0.9.5.dist-info/top_level.txt,sha256=hsENS-AlDVRh8tQJ6-426iUQlla9bPcGc0-UlFF0_iU,11
|
|
22
|
-
imsciences-0.9.5.dist-info/RECORD,,
|
|
17
|
+
imsciences-0.9.5.2.dist-info/LICENSE.txt,sha256=lVq2QwcExPX4Kl2DHeEkRrikuItcDB1Pr7yF7FQ8_z8,1108
|
|
18
|
+
imsciences-0.9.5.2.dist-info/METADATA,sha256=Zvfy7-y18I-ZFj4aTL18nJOPp57k4uwj5p5ajze5GwI,16994
|
|
19
|
+
imsciences-0.9.5.2.dist-info/PKG-INFO-IMS-24Ltp-3,sha256=yqZbigwHjnYoqyI81PGz_AeofRFfOrwH_Vyawyef-mg,854
|
|
20
|
+
imsciences-0.9.5.2.dist-info/WHEEL,sha256=ixB2d4u7mugx_bCBycvM9OzZ5yD7NmPXFRtKlORZS2Y,91
|
|
21
|
+
imsciences-0.9.5.2.dist-info/top_level.txt,sha256=hsENS-AlDVRh8tQJ6-426iUQlla9bPcGc0-UlFF0_iU,11
|
|
22
|
+
imsciences-0.9.5.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|