imsciences 0.6.1.5__py3-none-any.whl → 0.6.1.7__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/datafunctions.py +17 -7
- {imsciences-0.6.1.5.dist-info → imsciences-0.6.1.7.dist-info}/METADATA +1 -1
- {imsciences-0.6.1.5.dist-info → imsciences-0.6.1.7.dist-info}/RECORD +5 -5
- {imsciences-0.6.1.5.dist-info → imsciences-0.6.1.7.dist-info}/WHEEL +0 -0
- {imsciences-0.6.1.5.dist-info → imsciences-0.6.1.7.dist-info}/top_level.txt +0 -0
imsciences/datafunctions.py
CHANGED
|
@@ -209,8 +209,8 @@ class dataprocessing:
|
|
|
209
209
|
|
|
210
210
|
print("\n37. Replace substrings in column of strings")
|
|
211
211
|
print(" - Description: Replace substrings in column of strings based off dictionary, can also change column to lower")
|
|
212
|
-
print(" - Usage: replace_substrings(df, column, replacements, to_lower=False)")
|
|
213
|
-
print(" - Example: replace_substrings(df, 'Influencer Handle', replacement_dict, to_lower=True)")
|
|
212
|
+
print(" - Usage: replace_substrings(df, column, replacements, to_lower=False, new_column=None)")
|
|
213
|
+
print(" - Example: replace_substrings(df, 'Influencer Handle', replacement_dict, to_lower=True, new_column='Short Version')")
|
|
214
214
|
|
|
215
215
|
print("\n38. Add totals column")
|
|
216
216
|
print(" - Description: Sums all columns with the option to exclude an date column to create a total column")
|
|
@@ -1371,28 +1371,38 @@ class dataprocessing:
|
|
|
1371
1371
|
|
|
1372
1372
|
return df
|
|
1373
1373
|
|
|
1374
|
-
def replace_substrings(self, df, column, replacements, to_lower=False):
|
|
1374
|
+
def replace_substrings(self, df, column, replacements, to_lower=False, new_column=None):
|
|
1375
1375
|
"""
|
|
1376
1376
|
Replaces substrings in a column of a DataFrame based on a dictionary of replacements.
|
|
1377
|
-
Optionally converts the column values to lowercase.
|
|
1377
|
+
Optionally converts the column values to lowercase and allows creating a new column or modifying the existing one.
|
|
1378
1378
|
|
|
1379
1379
|
Args:
|
|
1380
1380
|
df (pd.DataFrame): The DataFrame containing the column to modify.
|
|
1381
1381
|
column (str): The column name where the replacements will be made.
|
|
1382
1382
|
replacements (dict): A dictionary where keys are substrings to replace and values are the replacement strings.
|
|
1383
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.
|
|
1384
1385
|
|
|
1385
1386
|
Returns:
|
|
1386
1387
|
pd.DataFrame: The DataFrame with the specified replacements made, and optionally with lowercase strings.
|
|
1387
1388
|
"""
|
|
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
|
+
|
|
1389
1398
|
# Apply substring replacements
|
|
1390
1399
|
for old, new in replacements.items():
|
|
1391
|
-
df[
|
|
1392
|
-
|
|
1400
|
+
df[temp_column] = df[temp_column].str.replace(old, new, regex=False)
|
|
1401
|
+
|
|
1393
1402
|
# Optionally convert to lowercase
|
|
1394
1403
|
if to_lower:
|
|
1395
|
-
df[
|
|
1404
|
+
df[temp_column] = df[temp_column].str.lower()
|
|
1405
|
+
|
|
1396
1406
|
return df
|
|
1397
1407
|
|
|
1398
1408
|
def add_total_column(self, df, exclude_col=None, total_col_name='Total'):
|
|
@@ -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=
|
|
5
|
+
imsciences/datafunctions.py,sha256=kSvo0MiPJuSquKMt0RNNAjcloij-FGgffunf-ZBTYGw,137112
|
|
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.1.
|
|
12
|
-
imsciences-0.6.1.
|
|
13
|
-
imsciences-0.6.1.
|
|
14
|
-
imsciences-0.6.1.
|
|
11
|
+
imsciences-0.6.1.7.dist-info/METADATA,sha256=VISHFJ2z2oHyTyD2T2B3yhd-F83Q5Kb-XL8cr4EzOlI,854
|
|
12
|
+
imsciences-0.6.1.7.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
13
|
+
imsciences-0.6.1.7.dist-info/top_level.txt,sha256=hsENS-AlDVRh8tQJ6-426iUQlla9bPcGc0-UlFF0_iU,11
|
|
14
|
+
imsciences-0.6.1.7.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|