Overview

7 AI and Advanced Data Transformations

The chapter introduces advanced data transformations as a core data engineering skill and shows how AI can simplify tasks that traditionally require deep expertise, constant context switching, and multiple tools. Rather than treating AI as a niche helper, it presents conversational prompting and structured outputs as a flexible way to handle messy, real-world data. Across the examples, the central idea is that AI can reduce manual effort while still fitting into standard data pipelines.

Several common transformation problems are explored in detail. For complex text processing, the chapter compares manual regex extraction from messy log files with AI-assisted extraction that uses prompts and schema enforcement to return structured fields. For nested and hierarchical data, it demonstrates flattening JSON such as a library catalog into tabular form using both Python and AI-driven Pydantic schemas, emphasizing that AI can adapt more easily when schemas change. It also covers entity resolution, showing how traditional string normalization and similarity scoring can be replaced or augmented by AI that reasons across names, emails, devices, IP addresses, and other signals.

The final transformation area focuses on time series and date-time handling, including timezone conversion, fiscal quarter assignment, business-day due-date calculations, and contribution analysis for transaction data. The chapter contrasts a detailed Python implementation with an AI workflow that follows the same logic through prompts and structured response models, highlighting greater flexibility with similar results. The lab ties everything together with messy CRM, onboarding, and transaction datasets, reinforcing the practical goal: use both Python and AI to clean, merge, standardize, and analyze complex data more efficiently, while still validating outputs carefully.

A single user appears under two separate accounts—one personal, one professional. Despite differences in name and email domain, shared signals like device ID and activity reveal an underlying connection. Entity resolution helps unify these records to build a complete view of the customer.

Lab Answers

Refer to the Chapter 7 Lab Jupyter Notebook for full answers.

1. Flattening Nested JSON with AI

The AI approach uses structured response parsing to extract nested data reliably:

This approach handles schema changes gracefully—if new nested fields are added, you simply update the prompt and data class without rewriting complex extraction logic.

2. Complex Text Processing with AI

AI excels at parsing messy text formats that would require complex regex patterns:

The AI approach adapts to format variations automatically and can handle new subscription types like ENTERPRISE3xHYBRID without code changes.

3. AI-Powered Entity Resolution

Instead of rule-based matching, AI performs sophisticated entity resolution by considering multiple factors:

The AI evaluates each customer against all others, providing confidence scores and detailed reasoning for matches. This handles edge cases like nickname variations and email format differences that rule-based systems often miss.

4. Time Series Transformations with AI

AI handles complex date-time transformations and business logic:

The AI correctly handles timezone conversions, business day calculations, and custom fiscal calendars without requiring complex date manipulation libraries.

5. Extra Credit: Build a Golden Account List

AI creates comprehensive B2B account profiles by analyzing combined customer and transaction data:

This produces actionable B2B intelligence by synthesizing customer demographics, spending patterns, and engagement metrics into prioritized account lists.The key advantage of the AI approach throughout this lab is adaptability—as data formats change, new subscription types are added, or business rules evolve, you update prompts rather than rewriting complex parsing and transformation logic. This makes AI-driven data engineering pipelines more maintainable and scalable for production environments.

FAQ

What is the main advantage of using AI for advanced data transformations in Chapter 7?AI provides a conversational, flexible way to handle complex transformations without requiring as much manual coding, tool switching, or specialized syntax knowledge as traditional methods.
How does regex help with processing messy log files?Regex lets you extract structured fields like log level, date, and time from unstructured log text, turning chaotic logs into query-ready data.
What are the risks of using AI to generate or apply regex patterns?AI can hallucinate fields, produce incorrect patterns, return inconsistent output formats, or overfit to examples, so outputs should always be validated against a schema or test set.
How does the AI approach for log extraction differ from the traditional regex approach?Instead of manually writing a regex pattern, you describe the fields you want in natural language and use a structured response model so the AI can extract the data for you.
Why is flattening nested JSON data important in data engineering?Nested JSON is hard to analyze directly. Flattening it into a tabular structure makes it easier to load into a DataFrame, query, and use in downstream pipelines.
How can AI help with hierarchical and nested data structures?AI can map nested data directly into a defined schema, reducing the need for custom parsing logic and making it easier to adapt when the structure changes.
What is entity resolution, and why is it important?Entity resolution identifies when different records actually refer to the same real-world entity, which is essential for building accurate customer profiles and golden records.
What is the limitation of the traditional entity resolution approach shown in Chapter 7?It requires manual decisions about normalization, similarity scoring, and weighting, and it does not explain why a match was chosen beyond the final score.
How does AI improve entity resolution compared to fuzzy matching alone?AI can reason across multiple fields at once, return a confidence score, and explain its reasoning in natural language, making the matching process more transparent and adaptable.
What kinds of time-series and date-time transformations are covered in this chapter?The chapter covers timezone conversion, extracting date parts like month and year, applying custom fiscal quarter rules, calculating business-day due dates, and computing contribution percentages by account.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Learn AI Data Engineering ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Learn AI Data Engineering ebook for free