imsciences 0.6.0.2__tar.gz → 0.6.0.3__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.
- {imsciences-0.6.0.2 → imsciences-0.6.0.3}/PKG-INFO +1 -1
- {imsciences-0.6.0.2 → imsciences-0.6.0.3}/imsciences/datafunctions.py +37 -5
- {imsciences-0.6.0.2 → imsciences-0.6.0.3}/imsciences.egg-info/PKG-INFO +1 -1
- {imsciences-0.6.0.2 → imsciences-0.6.0.3}/setup.py +1 -1
- {imsciences-0.6.0.2 → imsciences-0.6.0.3}/README.md +0 -0
- {imsciences-0.6.0.2 → imsciences-0.6.0.3}/imsciences/__init__.py +0 -0
- {imsciences-0.6.0.2 → imsciences-0.6.0.3}/imsciences.egg-info/SOURCES.txt +0 -0
- {imsciences-0.6.0.2 → imsciences-0.6.0.3}/imsciences.egg-info/dependency_links.txt +0 -0
- {imsciences-0.6.0.2 → imsciences-0.6.0.3}/imsciences.egg-info/requires.txt +0 -0
- {imsciences-0.6.0.2 → imsciences-0.6.0.3}/imsciences.egg-info/top_level.txt +0 -0
- {imsciences-0.6.0.2 → imsciences-0.6.0.3}/setup.cfg +0 -0
|
@@ -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
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|