Sustituye nombres, correos y números reales por datos ficticios usando Faker para compartir entornos de prueba seguros.
Replace real names, emails, and numbers with fictional data using Faker to share safe testing environments.
Este ejercicio es solo para aprendizaje y pruebas. No ejecutes scripts contra datos reales, ambientes de producción, APIs externas, portales con login, datos sensibles, sistemas críticos o repositorios empresariales sin autorización, respaldos, pruebas previas, permisos mínimos, control de cambios y cumplimiento de los protocolos de ciberseguridad de tu organización.
This exercise is for learning and testing only. Do not run scripts against real data, production environments, external APIs, login portals, sensitive data, critical systems, or enterprise repositories without authorization, backups, prior testing, least-privilege permissions, change control, and compliance with your organization's cybersecurity protocols.
Crear una copia segura de un dataset reemplazando campos sensibles por valores ficticios conservando la estructura.
Create a safe copy of a dataset by replacing sensitive fields with fictional values while preserving structure.
| nombre_real | email_real | departamento |
|---|---|---|
| Ana Perez | ana@example.com | IT |
| John Smith | john@example.com | HR |
from faker import Faker fake = Faker() df["nombre_seguro"] = df["nombre_real"].apply(lambda x: fake.name()) df["email_seguro"] = df["email_real"].apply(lambda x: fake.email())
| nombre_seguro | email_seguro | departamento |
|---|---|---|
| Laura Miller | karen45@example.net | IT |
| Daniel Brown | robert88@example.org | HR |
# ==========================================================
# Python Advanced Topic 17
# Sensitive Data Masking with Faker
# ==========================================================
# pip install faker pandas
import pandas as pd
from faker import Faker
fake = Faker()
df = pd.DataFrame({
"nombre_real": ["Ana Perez", "John Smith", "Maria Lopez"],
"email_real": ["ana@example.com", "john@example.com", "maria@example.com"],
"departamento": ["IT", "HR", "Finance"]
})
df_safe = df.copy()
df_safe["nombre_seguro"] = df_safe["nombre_real"].apply(lambda x: fake.name())
df_safe["email_seguro"] = df_safe["email_real"].apply(lambda x: fake.email())
# Remove original sensitive fields from the shareable file
df_safe = df_safe.drop(columns=["nombre_real", "email_real"])
df_safe.to_csv("dataset_enmascarado.csv", index=False)
print(df_safe)departamento nombre_seguro email_seguro 0 IT Laura Miller karen45@example.net 1 HR Daniel Brown robert88@example.org 2 Finance Sarah Davis sarah77@example.com
El enmascaramiento permite practicar y desarrollar con datos realistas sin exponer identidades reales.
Masking enables practice and development with realistic data without exposing real identities.