imsciences 0.6.1.6__tar.gz → 0.6.1.7__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.1.6 → imsciences-0.6.1.7}/PKG-INFO +1 -1
- {imsciences-0.6.1.6 → imsciences-0.6.1.7}/imsciences/datafunctions.py +33 -33
- {imsciences-0.6.1.6 → imsciences-0.6.1.7}/imsciences.egg-info/PKG-INFO +1 -1
- {imsciences-0.6.1.6 → imsciences-0.6.1.7}/setup.py +1 -1
- {imsciences-0.6.1.6 → imsciences-0.6.1.7}/README.md +0 -0
- {imsciences-0.6.1.6 → imsciences-0.6.1.7}/imsciences/__init__.py +0 -0
- {imsciences-0.6.1.6 → imsciences-0.6.1.7}/imsciences.egg-info/SOURCES.txt +0 -0
- {imsciences-0.6.1.6 → imsciences-0.6.1.7}/imsciences.egg-info/dependency_links.txt +0 -0
- {imsciences-0.6.1.6 → imsciences-0.6.1.7}/imsciences.egg-info/requires.txt +0 -0
- {imsciences-0.6.1.6 → imsciences-0.6.1.7}/imsciences.egg-info/top_level.txt +0 -0
- {imsciences-0.6.1.6 → imsciences-0.6.1.7}/setup.cfg +0 -0
|
@@ -1371,39 +1371,39 @@ class dataprocessing:
|
|
|
1371
1371
|
|
|
1372
1372
|
return df
|
|
1373
1373
|
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1374
|
+
def replace_substrings(self, df, column, replacements, to_lower=False, new_column=None):
|
|
1375
|
+
"""
|
|
1376
|
+
Replaces substrings in a column of a DataFrame based on a dictionary of replacements.
|
|
1377
|
+
Optionally converts the column values to lowercase and allows creating a new column or modifying the existing one.
|
|
1378
|
+
|
|
1379
|
+
Args:
|
|
1380
|
+
df (pd.DataFrame): The DataFrame containing the column to modify.
|
|
1381
|
+
column (str): The column name where the replacements will be made.
|
|
1382
|
+
replacements (dict): A dictionary where keys are substrings to replace and values are the replacement strings.
|
|
1383
|
+
to_lower (bool, optional): If True, the column values will be converted to lowercase before applying replacements. Default is False.
|
|
1384
|
+
new_column (str, optional): If provided, the replacements will be applied to this new column. If None, the existing column will be modified. Default is None.
|
|
1385
|
+
|
|
1386
|
+
Returns:
|
|
1387
|
+
pd.DataFrame: The DataFrame with the specified replacements made, and optionally with lowercase strings.
|
|
1388
|
+
"""
|
|
1389
|
+
|
|
1390
|
+
if new_column is not None:
|
|
1391
|
+
# Create a new column for replacements
|
|
1392
|
+
df[new_column] = df[column]
|
|
1393
|
+
temp_column = new_column
|
|
1394
|
+
else:
|
|
1395
|
+
# Modify the existing column
|
|
1396
|
+
temp_column = column
|
|
1397
|
+
|
|
1398
|
+
# Apply substring replacements
|
|
1399
|
+
for old, new in replacements.items():
|
|
1400
|
+
df[temp_column] = df[temp_column].str.replace(old, new, regex=False)
|
|
1401
|
+
|
|
1402
|
+
# Optionally convert to lowercase
|
|
1403
|
+
if to_lower:
|
|
1404
|
+
df[temp_column] = df[temp_column].str.lower()
|
|
1405
|
+
|
|
1406
|
+
return df
|
|
1407
1407
|
|
|
1408
1408
|
def add_total_column(self, df, exclude_col=None, total_col_name='Total'):
|
|
1409
1409
|
"""
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|