imsciences 0.6.0.2__py3-none-any.whl → 0.6.0.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.
@@ -184,7 +184,12 @@ class dataprocessing:
184
184
  print("\n32. upgrade all packages")
185
185
  print(" - Description: Upgrades all packages.")
186
186
  print(" - Usage: upgrade_outdated_packages()")
187
- print(" - Example: upgrade_outdated_packages()")
187
+ print(" - Example: upgrade_outdated_packages()")
188
+
189
+ print("\n33. Convert Mixed Formats Dates")
190
+ print(" - Description: Convert a mix of US and UK dates to datetime.")
191
+ print(" - Usage: convert_mixed_formats_dates(df, datecol)")
192
+ print(" - Example: convert_mixed_formats_dates(df, 'OBS')")
188
193
 
189
194
  def get_wd_levels(self, levels):
190
195
  """
@@ -602,10 +607,6 @@ class dataprocessing:
602
607
  )
603
608
  return df
604
609
 
605
- # Apply the fix to the specified column
606
- df[date_col] = df[date_col].apply(lambda x: fix_date(x) if not pd.isnull(x) else x)
607
- return df
608
-
609
610
  def combine_sheets(self, all_sheets):
610
611
  """
611
612
  Combines multiple DataFrames from a dictionary into a single DataFrame.
@@ -1229,6 +1230,37 @@ class dataprocessing:
1229
1230
  except Exception as e:
1230
1231
  print(f"An error occurred during the upgrade process: {e}")
1231
1232
 
1233
+ def convert_mixed_formats_dates(self, df, column_name):
1234
+ # Convert initial dates to datetime with coercion to handle errors
1235
+ df[column_name] = pd.to_datetime(df[column_name], errors='coerce')
1236
+ df[column_name] = df[column_name].astype(str)
1237
+ corrected_dates = []
1238
+
1239
+ for date_str in df[column_name]:
1240
+ date_str = date_str.replace('-', '').replace('/', '')
1241
+ if len(date_str) == 8:
1242
+ year = date_str[:4]
1243
+ month = date_str[4:6]
1244
+ day = date_str[6:8]
1245
+ if int(day) <= 12:
1246
+ # Swap month and day
1247
+ corrected_date_str = f"{year}-{day}-{month}"
1248
+ else:
1249
+ corrected_date_str = f"{year}-{month}-{day}"
1250
+ # Convert to datetime
1251
+ corrected_date = pd.to_datetime(corrected_date_str, errors='coerce')
1252
+ else:
1253
+ corrected_date = pd.to_datetime(date_str, errors='coerce')
1254
+
1255
+ corrected_dates.append(corrected_date)
1256
+
1257
+ # Check length of the corrected_dates list
1258
+ if len(corrected_dates) != len(df):
1259
+ raise ValueError("Length of corrected_dates does not match the original DataFrame")
1260
+
1261
+ # Assign the corrected dates back to the DataFrame
1262
+ df[column_name] = corrected_dates
1263
+ return df
1232
1264
 
1233
1265
 
1234
1266
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: imsciences
3
- Version: 0.6.0.2
3
+ Version: 0.6.0.3
4
4
  Summary: IMS Data Processing Package
5
5
  Author: IMS
6
6
  Author-email: cam@im-sciences.com
@@ -2,13 +2,13 @@ dataprocessing/__init__.py,sha256=quSwsLs6IuLoA5Rzi0ZD40xZaQudwDteF7_ai9JfTPk,32
2
2
  dataprocessing/data-processing-functions.py,sha256=vE1vsZ8xOSbR9Bwlp9SWXwEHXQ0nFydwGkvzHXf2f1Y,41
3
3
  dataprocessing/datafunctions.py,sha256=vE1vsZ8xOSbR9Bwlp9SWXwEHXQ0nFydwGkvzHXf2f1Y,41
4
4
  imsciences/__init__.py,sha256=GIPbLmWc06sVcOySWwNvMNUr6XGOHqPLryFIWgtpHh8,78
5
- imsciences/datafunctions.py,sha256=vrv-6H8iccN23bdn5OqBHLsWfscrKOWvVyAtrlkgyd4,132385
5
+ imsciences/datafunctions.py,sha256=DKK03w47pFXl5xTPZ_0CdCmJP_IVwT1OLBVzK5-QjGU,133927
6
6
  imsciences/datapull.py,sha256=TPY0LDgOkcKTBk8OekbD0Grg5x0SomAK2dZ7MuT6X1E,19000
7
7
  imsciencesdataprocessing/__init__.py,sha256=quSwsLs6IuLoA5Rzi0ZD40xZaQudwDteF7_ai9JfTPk,32
8
8
  imsciencesdataprocessing/datafunctions.py,sha256=vE1vsZ8xOSbR9Bwlp9SWXwEHXQ0nFydwGkvzHXf2f1Y,41
9
9
  imsdataprocessing/__init__.py,sha256=quSwsLs6IuLoA5Rzi0ZD40xZaQudwDteF7_ai9JfTPk,32
10
10
  imsdataprocessing/datafunctions.py,sha256=vE1vsZ8xOSbR9Bwlp9SWXwEHXQ0nFydwGkvzHXf2f1Y,41
11
- imsciences-0.6.0.2.dist-info/METADATA,sha256=jB4rv8_8NBrTNNUi1WWT7-WZ5R2u11IxJIieDQJ5hm8,11571
12
- imsciences-0.6.0.2.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
13
- imsciences-0.6.0.2.dist-info/top_level.txt,sha256=hsENS-AlDVRh8tQJ6-426iUQlla9bPcGc0-UlFF0_iU,11
14
- imsciences-0.6.0.2.dist-info/RECORD,,
11
+ imsciences-0.6.0.3.dist-info/METADATA,sha256=8_UQYWlXnPmBctZ1w9wGltM-DN-PQmovqiQ9ERxe7Ng,11571
12
+ imsciences-0.6.0.3.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
13
+ imsciences-0.6.0.3.dist-info/top_level.txt,sha256=hsENS-AlDVRh8tQJ6-426iUQlla9bPcGc0-UlFF0_iU,11
14
+ imsciences-0.6.0.3.dist-info/RECORD,,