Spaces:
Runtime error
Runtime error
Create utils.py
Browse files
utils.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import random
|
| 2 |
+
import string
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def anonymize_column(col):
|
| 6 |
+
"""
|
| 7 |
+
Anonymizes a column by replacing all values with a random string of 10 characters.
|
| 8 |
+
|
| 9 |
+
Args:
|
| 10 |
+
col (pandas.Series): A pandas Series object representing a column of data.
|
| 11 |
+
|
| 12 |
+
Returns:
|
| 13 |
+
pandas.Series: The anonymized column as a pandas Series object.
|
| 14 |
+
"""
|
| 15 |
+
def generate_random_string():
|
| 16 |
+
"""
|
| 17 |
+
Generates a random string of 10 characters.
|
| 18 |
+
|
| 19 |
+
Returns:
|
| 20 |
+
str: The random string.
|
| 21 |
+
"""
|
| 22 |
+
return ''.join(random.choices(string.ascii_letters + string.digits, k=10))
|
| 23 |
+
|
| 24 |
+
return col.apply(lambda x: generate_random_string())
|