⚠️ Advertencia crítica antes de correr cualquier script
No ejecutes scripts de Python contra archivos oficiales, bases de datos reales, carpetas institucionales, SQL Server, Access, APIs internas o datasets sensibles sin autorización formal.
Python puede transformar miles o millones de filas en segundos. Un cambio mal probado puede sobrescribir archivos, alterar columnas críticas, crear resultados incorrectos, exponer datos sensibles o afectar procesos de BI, auditoría o producción.
Regla obligatoria del training: primero se trabaja con data sintética, luego con una copia controlada, después se valida el resultado, y solo entonces se considera usar datos reales siguiendo permisos, backup, change control, data governance y protocolos de ciberseguridad.
- Permisos: usa solamente archivos y fuentes donde tengas autorización explícita.
- Backups: nunca sobrescribas data original sin una copia recuperable.
- Data governance: respeta privacidad, controles de acceso y clasificación de datos.
- Producción: nunca conectes scripts a fuentes reales sin revisión, aprobación y plan de reversa.
⚠️ Critical warning before running any script
Do not run Python scripts against official files, real databases, institutional folders, SQL Server, Access, internal APIs, or sensitive datasets without formal authorization.
Python can transform thousands or millions of rows in seconds. A poorly tested change can overwrite files, alter critical columns, create incorrect outputs, expose sensitive data, or affect BI, audit, or production processes.
Mandatory training rule: start with synthetic data, then use a controlled copy, validate the result, and only then consider real data while following permissions, backups, change control, data governance, and cybersecurity protocols.
- Permissions: use only files and sources where you have explicit authorization.
- Backups: never overwrite original data without a recoverable copy.
- Data governance: respect privacy, access controls, and data classification.
- Production: never connect scripts to real sources without review, approval, and rollback planning.
Objetivo del Topic 10
Agrega columnas que indiquen qué registros necesitan revisión humana.
Topic 10 Objective
Add columns that show which records need human review.
Ruta de trabajo
Todo se ejecuta dentro de una carpeta controlada:
Working folder
Everything runs inside a controlled folder:
base_path = Path.home() / "Documents" / "AI Practical Training" / "Python" / "Topic 10"Qué vamos a aprender
- Crear data sintética controlada.
- Leer y transformar datos con pandas.
- Aplicar una regla de limpieza o validación.
- Exportar resultados para revisión.
- Verificar el resultado antes de usar datos reales.
What you will learn
- Create controlled synthetic data.
- Read and transform data with pandas.
- Apply a cleaning or validation rule.
- Export results for review.
- Verify the result before using real data.
Script 1 — Crear data sintética
Este script prepara datos de práctica para ejecutar el ejercicio sin tocar información real.
Script 1 — Create synthetic data
This script prepares practice data to run the exercise without touching real information.
# Python Topic 10 - Script 1
from pathlib import Path
import pandas as pd
base_path = Path.home() / "Documents" / "AI Practical Training" / "Python" / "Topic 10"
data_path = base_path / "Data"
data_path.mkdir(parents=True, exist_ok=True)
raw_file = data_path / "employees_for_flags.xlsx"
df = pd.DataFrame({
"employee_id": ["10001", None, "10003", "10004"],
"email": ["john@x.com", "maria@x.com", None, "ana@x.com"],
"status": ["Active", "Active", "Inactive", "Active"]
})
df.to_excel(raw_file, index=False)
print("Flag practice file created:", raw_file)Script 2 — Ejecutar la acción principal
Este script aplica la lógica central del topic y genera el resultado principal.
Script 2 — Run the main action
This script applies the core topic logic and generates the main result.
# Python Topic 10 - Script 2
from pathlib import Path
import pandas as pd
base_path = Path.home() / "Documents" / "AI Practical Training" / "Python" / "Topic 10"
data_path = base_path / "Data"
df = pd.read_excel(data_path / "employees_for_flags.xlsx")
df["missing_employee_id"] = df["employee_id"].isna()
df["missing_email"] = df["email"].isna()
df["inactive_status"] = df["status"].eq("Inactive")
df["needs_review"] = df[["missing_employee_id", "missing_email", "inactive_status"]].any(axis=1)
review_queue = df[df["needs_review"]].copy()
df.to_excel(data_path / "employees_with_flags.xlsx", index=False)
review_queue.to_excel(data_path / "review_queue.xlsx", index=False)
print("Flags created.")
print(review_queue)Script 3 — Verificar o reportar resultados
Este script confirma el resultado final o genera evidencia para revisión.
Script 3 — Verify or report results
This script confirms the final result or generates evidence for review.
# Python Topic 10 - Script 3
from pathlib import Path
import pandas as pd
base_path = Path.home() / "Documents" / "AI Practical Training" / "Python" / "Topic 10"
df = pd.read_excel(base_path / "Data" / "employees_with_flags.xlsx")
print(df[["employee_id", "missing_employee_id", "missing_email", "inactive_status", "needs_review"]])
print(df["needs_review"].value_counts(dropna=False))Explicación simple del script
- Path crea rutas portables en Windows.
- pandas lee, transforma y exporta la tabla.
- El Script 1 crea data sintética para practicar sin riesgo.
- El Script 2 aplica la lógica principal del topic.
- El Script 3 valida el resultado y deja evidencia.
Simple script explanation
- Path creates portable Windows paths.
- pandas reads, transforms, and exports the table.
- Script 1 creates synthetic data for safe practice.
- Script 2 applies the main topic logic.
- Script 3 validates the result and leaves evidence.
Ejemplo esperado
| Caso | Resultado |
|---|---|
| Missing ID | needs_review |
| Missing email | needs_review |
| Inactive | needs_review |
Expected example
| Case | Result |
|---|---|
| Missing ID | needs_review |
| Missing email | needs_review |
| Inactive | needs_review |
Conclusión
Banderas de excepción hacen visible qué debe revisar una persona antes de avanzar.
Conclusion
Exception flags make it visible what a person must review before moving forward.