Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Challenge: Compliance Data Dashboard | Analyzing and Visualizing Compliance Data
/
Python for Compliance Officers
Sección 2. Capítulo 5
single

single

bookChallenge: Compliance Data Dashboard

Desliza para mostrar el menú

As you approach the challenge of building a compliance data dashboard, recall how pandas enables you to efficiently analyze transaction data and how matplotlib helps you visualize patterns that may be relevant for compliance monitoring. These tools are essential for summarizing large datasets, identifying anomalies, and communicating findings to stakeholders in a compliance context.

123456789101112131415161718192021222324252627282930313233343536
import pandas as pd import matplotlib.pyplot as plt # Hardcoded transaction data data = { "id": [1, 2, 3, 4, 5, 6, 7, 8], "amount": [1200, 500, 3200, 1500, 700, 2200, 4000, 800], "account_id": ["A01", "A02", "A01", "A03", "A02", "A01", "A03", "A02"] } df = pd.DataFrame(data) # Calculate summary statistics total_amount = df["amount"].sum() average_amount = df["amount"].mean() max_amount = df["amount"].max() print("Total transaction amount:", total_amount) print("Average transaction amount:", average_amount) print("Maximum transaction amount:", max_amount) # Aggregate by account for bar chart account_totals = df.groupby("account_id")["amount"].sum() account_totals.plot(kind="bar", title="Total Transaction Amounts per Account") plt.xlabel("Account ID") plt.ylabel("Total Amount") plt.tight_layout() plt.show() # Identify anomalies: transactions > 2 std dev above mean mean_amount = df["amount"].mean() std_amount = df["amount"].std() anomaly_threshold = mean_amount + 2 * std_amount anomalies = df[df["amount"] > anomaly_threshold] print("Transactions above anomaly threshold (2 std dev):") print(anomalies)
copy

To structure your compliance dashboard, follow a clear sequence: start by loading and summarizing your transaction data, using pandas to calculate totals and averages. Next, use matplotlib to visualize aggregated results, such as total transactions per account, to spot trends or concentrations. Finally, apply statistical analysis to flag any transactions that are unusually large—those that are more than two standard deviations above the mean—helping you quickly detect potential compliance risks.

Tarea

Swipe to start coding

Build a Python script that acts as a compliance data dashboard. The script must:

  • Calculate the total, average, and maximum transaction amount from the DataFrame.
  • Aggregate transaction amounts by account and prepare the data for a bar chart visualization.
  • Identify all transactions where the amount is more than two standard deviations above the mean.
  • Store all results in variables as referenced in the starter code.

Solución

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 5
single

single

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

some-alt