INNER CODE UNIT · Python
removed_count
balapriyac/data-science-tutorials · build-with-python/etl-pipeline/main.py:47
removed_count = initial_count - len(df_clean)
print(f"Removed {removed_count} records with missing emails")
# Calculate derived fields
df_clean['total_amount'] = df_clean['price'] * df_clean['quantity']
# Extract date components for better analysis
df_clean['transaction_date'] = pd.to_datetime(df_clean['transaction_date'])
df_clean['year'] = df_clean['transaction_date'].dt.year
df_clean['month'] = df_clean['transaction_date'].dt.month
df_clean['day_of_week'] = df_clean['transaction_date'].dt.day_name()
# Create customer segments based on spending
df_clean['customer_segment'] = pd.cut(df_clean['total_amount'],
bins=[0, 50, 200, float('inf')],
labels=['Low', 'Medium', 'High'])
print(f"Transformation complete. {len(df_clean)} clean records ready")