Page
1
(This page has no text content)
Page
2
MEAP Edition Manning Early Access Program Learn AI Data Engineering Version 8 Copyright 2026 Manning Publications For more information on this and other Manning titles go to manning.com. © Manning Publications Co. To comment go to liveBook Licensed to Ibrahim Mohammed Mohammed <ibrahim@dotnetebusiness.com>
Page
3
welcome Thank you for purchasing the MEAP edition of Learn AI Data Engineering. Writing this book has been one of the most rewarding challenges of my career. AI and LLMs are moving fast, but that only proves how urgent it is to understand how to use them with purpose, not just curiosity. This book was born from a simple frustration. Data work has become too complex. Somewhere along the way, we let tooling, infrastructure, and admin tasks take over the job. Data engineers are now expected to spend more time figuring out platform permissions and YAML configurations than actually working with data. We have overindexed on tools and lost the plot. This book is my attempt to bring it back. You’ll learn how to work directly with AI, how to build smarter workflows, and how to use LLMs in a programmatic, repeatable way. We’ll keep things practical. You’ll write SQL and Python, you’ll hit real APIs, and you’ll work through labs that are grounded in the kinds of problems data engineers deal with every week. More than anything, I hope this book helps you get time back. When I started out in data, my Monday mornings were full of dread. Pipelines would break, edge cases would surface, and I would find myself neck-deep in brittle logic just trying to stay afloat. But for the first time, I can say that AI has helped me break that cycle. Whether it's improving data quality, generating new insights, or simplifying code that used to feel impossible, this is the closest I’ve come to actually enjoying the process again. I hope this book gives you that feeling too. Less friction. More clarity. And a better way to focus on what really matters—solving problems with data. Please be sure to post any questions, comments, or suggestions you have about the book in the liveBook discussion forum. Thanks again for joining me. I can’t wait to see what you build. —David Melillo © Manning Publications Co. To comment go to liveBook Licensed to Ibrahim Mohammed Mohammed <ibrahim@dotnetebusiness.com>
Page
4
brief contents PART 1: CORE CONCEPTS OF DATA ENGINEERING WITH AI 1 Before You Begin 2 Advantages & Disadvantages of Using a Coding Companion 3 Using a Coding Companion with SQL 4 Using a Coding Companion with Python 5 Using the OpenAI API in Data Workflows PART 2: DATA CLEANING AND TRANSFORMATION PIPELINES WITH AI 6 AI & Data Quality 7 AI and Advanced Data Transformations 8 AI and The Data Lifecycle 9 Data Cleaning and Transformation Pipelines in Practice PART 3: GENERATING DATA WITH AI 10 Introduction to Web Scraping 11 Identifying Opportunities for AI-Generated Data 12 AI-powered web scraping data pipelines in action Appendix A. Setting Up Your Environment Appendix B. Prompt Engineering Reference Appendix C. Using the OpenAI API Appendix D. Troubleshooting Common Errors © Manning Publications Co. To comment go to liveBook Licensed to Ibrahim Mohammed Mohammed <ibrahim@dotnetebusiness.com>
Page
5
Part 1 Core Concepts of Data Engineering with AI Every productive partnership starts with knowing what your partner is good at, and where it will let you down. Part 1 builds that working relationship with the AI coding companion before you point it at anything that matters. You will start by getting set up and getting honest about what these tools can and cannot do: where an LLM accelerates real data engineering work, and where it confidently invents a column that does not exist or a library function that was never there (chapters 1 and 2). From there you put the companion to work in the two languages you live in. Chapter 3 walks through prompting techniques for SQL, from zero-shot and few-shot to chain-of-thought and beyond, using a database the model already knows well. Chapter 4 does the same for Python: calling APIs, untangling nested JSON, and generating the kind of regular expressions nobody enjoys writing by hand. The part closes by changing how you talk to the model at all. In chapter 5 you stop pasting prompts into a chat window and start calling the OpenAI API directly from your code, turning a conversational helper into a programmable component you can build a pipeline around. By the end of Part 1 you will have the instincts, and the guardrails, to let AI move you faster without driving you off a cliff. 1 © Manning Publications Co. To comment go to liveBook Licensed to Ibrahim Mohammed Mohammed <ibrahim@dotnetebusiness.com>
Page
6
1 Before You Begin The AI movement marks one of the most defining technological shifts of the 21st century. It echoes the internet boom of the 1990s and the rise of cloud computing in the 2000s. Earlier waves of artificial intelligence in the 20th century fell short due to limited compute power, rigid rule-based systems, and inflated expectations. Modern AI has advanced with scalable models, vast datasets, and real-world applications that finally deliver on decades of promise. This shift is reshaping every industry. Artists face AI-generated work challenging their creative boundaries. Educators grapple with distinguishing genuine student comprehension. Software engineers now question the need for deep syntax knowledge when models can generate boilerplate code with a single prompt. The question arises: could non-technical individuals replace entire development teams simply by mastering prompt engineering? This book does not attempt to resolve that existential question. Instead, it focuses on how AI enhances rather than replaces human intelligence. AI empowers skilled professionals, including developers, analysts, and engineers, to automate mundane tasks and concentrate on high-value work that demands creativity, critical thinking, and problem- solving. While emerging agentic systems, which are AI tools capable of initiating actions or decisions without constant human prompting, may continue to evolve, the most effective professionals will likely be those who use AI to eliminate drudgery, not those who resist its integration into their workflows. 1.1 Why AI Matters to Data Engineering Data engineering is a field with a broad range of responsibilities. Engineers integrate and process data from various sources, apply business transformations, orchestrate workflows, and maintain cost-effective operations across distributed systems. While specializations vary, many data engineers aim to deliver direct business value through code and data products, rather than spending time on configuration or infrastructure management. As AI increasingly handles abstract or repetitive infrastructure tasks, data engineers will be expected to move even closer to the business, focusing on logic, insight, and impact. 2 © Manning Publications Co. To comment go to liveBook Licensed to Ibrahim Mohammed Mohammed <ibrahim@dotnetebusiness.com>
Page
7
AI presents a compelling opportunity as a coding companion, generating code that is often accurate enough to use with minimal refinement. Tools like ChatGPT, GitHub Copilot, and Claude have already begun replacing repetitive scripting, scaffolding complex data pipelines, and offering natural language interfaces to libraries like pandas, NumPy, and scikit-learn. The true potential of AI in data engineering is still unfolding. Large language models are not only generating solutions but also acting as reviewers—critiquing prompts, debugging code, and comparing implementation options across libraries or frameworks. This evolution points toward a future where a single, language-based tool could replace dozens of specialized libraries within a unified and intelligent developer workflow. While this book focuses squarely on data engineering, it’s worth stepping back for a moment to see where that role fits within the broader data ecosystem. Data engineers don’t work in isolation. They build the infrastructure that supports analysts and data scientists alike. By comparing the tasks and tooling of each persona, we can better appreciate how AI amplifies value across the board. Whether it’s auto-generating SQL for analysts, suggesting features for scientists, or transforming raw data for engineers, AI reveals its versatility as a developer’s Swiss Army knife. This comparison not only highlights the depth of AI’s potential in data engineering but also helps any reader—from analyst to architect—grasp why these capabilities are so transformative for the entire data lifecycle. 3 © Manning Publications Co. To comment go to liveBook Licensed to Ibrahim Mohammed Mohammed <ibrahim@dotnetebusiness.com>
Page
8
Table 1.1 Data Personas, Common Tasks and AI Supplementation Persona Common Tasks How AI Assists Data Engineer - Ingesting data from APIs and databases - Building data pipelines (ETL/ELT) - Managing data quality and validation - Transforming and storing structured data - Automates pipeline steps - Coding Companion - Imputes missing data or flags anomalies - Converts unstructured inputs into structured formats Data Scientist - Feature engineering - Running experiments and models - Evaluating performance metrics - Visualizing patterns and insights - Suggests or automates feature engineering - Summarizes high-level trends and statistical insights - Speeds up exploratory data analysis (EDA) - Prototypes models and refines hypotheses Data Analyst - Writing SQL queries for reports - Creating dashboards and charts - Generating ad-hoc business insights - Answering stakeholder data questions - Translates plain English to SQL (e.g., “Which customers spent most last month?”) - Automates repetitive analysis and summarization - Streamlines chart and dashboard creation with auto-insights - Flags anomalies or trends By the end of this book, you should see AI not as a shortcut but as a powerful multi-tool, enabling rapid development, automation of tedious tasks, and deeper insights into where human intervention is necessary for optimal outcomes. 1.2 Is This Book for You? AI is omnipresent. Countless blogs, courses, and debates discuss the "right" way to use AI and which platform is best. This book is designed for those working with data who want to move beyond simple ChatGPT prompts or AI-assisted coding in their IDEs. While we’ll cover the basics of AI coding companions, the real value lies in programmatic applications for data ingestion, transformation, and enrichment at scale. 4 © Manning Publications Co. To comment go to liveBook Licensed to Ibrahim Mohammed Mohammed <ibrahim@dotnetebusiness.com>
Page
9
This book will be valuable to experienced data engineers looking to automate repetitive work and enhance their pipelines with AI. Analysts and data scientists will find it useful for extracting structured data from unstructured sources. AI enthusiasts who want to scale their AI applications beyond interactive chatbots and into operational data workflows will also benefit. While familiarity with SQL, Python, and AI concepts will help readers get started quickly, the book is designed to be practical and hands-on, making it accessible to a broad audience. 1.2.1 The Many Uses for AI Artificial intelligence (AI) has seamlessly integrated into everyday life, transforming the manner in which interactions with technology occur. Consider virtual assistants such as Siri, Alexa, and Google Assistant. These AI-powered tools aid in performing simple tasks, from setting reminders to conducting web searches. In the realm of transportation, self-driving cars employ AI for real-time decision-making. In healthcare, AI-powered diagnostics support physicians in analyzing medical scans and predicting patient outcomes. Take, for example, Google Vertex AI, a cloud-based AI service for enterprises. This platform offers a suite of machine learning tools that can automate and streamline various business processes. It can analyze large amounts of data to provide actionable insights, predict customer behavior, and even optimize marketing campaigns. Streaming services, including Netflix, Spotify, and YouTube, leverage AI to provide personalized recommendations. Financial institutions utilize AI-driven fraud detection systems to identify suspicious transactions. Language translation tools, powered by AI, dismantle communication barriers. Furthermore, AI boosts e-commerce through chatbots, dynamic pricing, and inventory management. Beyond these familiar applications, AI is transforming the data engineering landscape. AI can automate data cleansing and transformation, ensuring inconsistencies are detected and corrected efficiently. It can extract meaningful features from raw, unstructured data, generate synthetic datasets for testing, and enhance natural language processing tasks like entity recognition and sentiment analysis. AI also plays a crucial role in data governance by detecting anomalies, enforcing data policies, and streamlining compliance efforts. These applications will be explored in depth throughout this book. 1.2.2 The Many Flavors of AI The AI landscape is driven by a rapidly growing set of large language models (LLMs), each offering different capabilities, design philosophies, and levels of openness. These LLMs power a variety of tools—from chat interfaces to embedded developer assistants—but at their core, they share a common function: generating and reasoning over natural language with machine-learned patterns. This book focuses primarily on OpenAI’s GPT models due to their widespread use and strong alignment with data engineering workflows. However, it is important to understand the broader ecosystem of LLM providers, especially as the market continues to evolve. 5 © Manning Publications Co. To comment go to liveBook Licensed to Ibrahim Mohammed Mohammed <ibrahim@dotnetebusiness.com>
Page
10
Below is a comparison of some of the most notable LLM families, highlighting their core strengths and trade-offs. Understanding these distinctions will help you select the right tool for a given use case and recognize how these models are shaping the future of AI development. Table 1.2 The Many Flavors of AI LLM Provider Strengths Limitations OpenAI GPT (3.5, 4, 4o) Industry-leading reasoning, coding, and plugin ecosystem. Strong developer tooling and APIs. Closed source. Cost may increase at scale. Lacks transparency on training data. Anthropic Claude Emphasis on safety, transparency, and long context windows. Strong reasoning with structured data. Slightly weaker code generation. Limited tool integration as of mid-2025. Google Gemini (Vertex AI) Deep integration with GCP. Strong in multi-modal and enterprise NLP tasks. Less intuitive dev experience. Closed ecosystem with steeper learning curve. Meta LLaMA Open-source models with strong academic and research community support. Requires infrastructure setup. Not optimized for production use out of the box. Mistral Lightweight, fast, and open. Great for edge devices and efficiency-focused workflows. Smaller context window. Fewer alignment features and safety controls. xAI Grok Built for real-time reasoning and access to live web data. Integrated tightly with the X platform. Early in development. Limited third-party access. Use cases still emerging. Cohere Command R Optimized for retrieval-augmented generation (RAG). Fine-tuned for enterprise document QA. Smaller ecosystem. Focused primarily on B2B scenarios. AI21 Labs (Jurassic) Flexible fine-tuning and strong structured output formatting. Less popular tooling. Weaker community support. 6 © Manning Publications Co. To comment go to liveBook Licensed to Ibrahim Mohammed Mohammed <ibrahim@dotnetebusiness.com>
Page
11
1.3 How to Use This Book This book follows the Month of Lunches format, designed so that you can complete one chapter per day. While you don’t have to read during lunch, each chapter is structured to take about 40 minutes to read, leaving you 20 minutes to practice what you’ve learned. 1.3.1 The Main Chapters Early chapters introduce key concepts such as AI coding companions and prompt engineering. Mid-book sections dive into data transformations, feature extraction, and AI- powered automation. Advanced topics cover structured data extraction, agentic workflows, and programmatic AI applications. 1.3.2 Hands-on Labs Nearly every chapter includes a short lab exercise to reinforce the material. These aren’t quizzes but hands-on opportunities to build real-world AI-enhanced data workflows. While solutions are provided, I strongly encourage working through the exercises yourself first. 1.3.3 Chapter Setup Files Each chapter in this book includes a dedicated setup guide located in the companion GitHub repository. These setup files are designed to help you get your environment up and running with minimal friction, ensuring you're ready to dive into the hands-on exercises without wasting time on configuration issues. Setup guides include all the technical details you need: software prerequisites, installation steps, environment variables, API key management, dataset instructions, and troubleshooting tips. For example, Chapter 1's setup file walks you through cloning the repo, installing dependencies, configuring environment variables, and verifying your OpenAI API connection. You'll also find links to sample data and ready-to-run Jupyter notebooks. These setup files are especially useful if you're unfamiliar with managing virtual environments or API keys. They're also a great resource for revisiting chapters later without having to reconfigure everything from scratch. Each setup is tailored to that chapter's focus, so be sure to follow the instructions before starting the hands-on labs. You can find the complete list of setup files in the setup/ directory of the GitHub repository, organized by chapter. 1.4 Setting Up Your Environment Before diving into examples, you’ll need to set up your local environment. This includes installing PostgreSQL and pgAdmin for SQL exercises, Jupyter Lab for Python workflows, and creating an OpenAI account for AI-powered tasks. Each setup is simple and fully documented in the linked GitHub repo. Once complete, you’ll be ready to follow along with every example in this book. 7 © Manning Publications Co. To comment go to liveBook Licensed to Ibrahim Mohammed Mohammed <ibrahim@dotnetebusiness.com>
Page
12
1.4.1 Installing PostgreSQL and pgAdmin We will be using PostgreSQL for SQL-based examples. You can find installation instructions in my GitHub repo: https://github. com/dave- melillo/data_ eng_ai/blob/ main/setup/ postgres_ setup.md 1.4.2 Installing Jupyter Lab for Python Work For Python-based exercises, we will use Jupyter Lab. Installation instructions and sample notebooks are available in the GitHub repo: https://github. com/dave- melillo/data_ eng_ai/blob/ main/setup/ jupyter_setup. md 1.4.3 Creating an OpenAI Account To follow along with AI-driven examples, you will need an OpenAI API key. Sign up at OpenAI and generate an API token. Again, an extensive installation and setup guide is available here: https://github. com/dave- melillo/data_ eng_ai/blob/ main/setup/ openai_setup. md 1.5 Being Immediately Effective with AI and Data Engineering This book is about practical application. While many books dive deep into LLM architectures and AI theory, this book is about making you effective immediately. By the end of the first few chapters, you’ll be using AI to generate and validate SQL queries, clean and transform datasets, extract insights from unstructured data, automate feature engineering, and integrate AI into your data pipelines. This book is designed to be hands-on, applied, and immediately useful. Let’s get started! 8 © Manning Publications Co. To comment go to liveBook Licensed to Ibrahim Mohammed Mohammed <ibrahim@dotnetebusiness.com>
Page
13
2 Advantages & Disadvantages of Using a Coding Companion The integration of large language models (LLMs), such as OpenAI’s ChatGPT, into data engineering workflows has transformed the way developers approach coding tasks. What began as conversational AI tools designed to generate human-like text has evolved into sophisticated coding companions capable of assisting with everything from simple SQL queries to complex data transformations. The real value of these models lies not just in their ability to produce code, but in how they enhance productivity, reduce manual effort, and streamline the iterative development process. In data engineering, where tasks often involve complex data pipelines, nested JSON structures, and fragile logic, LLMs offer meaningful advantages. They accelerate code generation, streamline repetitive tasks, and enable rapid prototyping with minimal input. However, this efficiency carries risks. LLMs do not possess true understanding of data relationships, system architecture, or business goals. As a result, they can introduce subtle errors or generate confident but incorrect responses. These AI-specific inaccuracies, known as hallucinations, are one of the most important limitations to watch for when integrating LLMs into real-world workflows. 9 © Manning Publications Co. To comment go to liveBook Licensed to Ibrahim Mohammed Mohammed <ibrahim@dotnetebusiness.com>
Page
14
WHAT CAN GO WRONG: HALLUCINATIONS A hallucination occurs when an AI model confidently produces incorrect or misleading information. In the context of data engineering, hallucinations might include generating nonexistent function names, inventing columns that aren’t present in a dataset, or proposing logic that appears valid but violates business rules. Because LLMs are trained on vast but imperfect data, they sometimes "fill in the blanks" with plausible but false details. Examples of Hallucination in Code Suggesting a method that doesn’t exist in the pandas library Referencing a column that isn't in the dataset Generating SQL that appears correct but fails on execution due to invalid joins How to Handle It Always validate generated code against your actual schema and business context Treat AI output as a first draft, not production-ready Use prompt feedback loops to refine and correct mistakes Key Takeaway: LLMs can accelerate development, but their confidence can be misleading. Human review is not optional—it’s critical. This chapter focuses on the benefits and trade-offs of using AI and LLM coding companions in data engineering. You’ll see how these tools can simplify coding tasks, reduce common errors, and accelerate development workflows. At the same time, we’ll look at their limitations, including the need for precise prompting, the difficulty of handling edge cases, and the importance of keeping human oversight in place for critical decisions. By the end of the chapter, you’ll understand how to use LLMs effectively—knowing when to trust their output and when to step in with your own judgment. 2.1 Mental Model: The Data Engineer and the Coding Companion Before we get into code and prompts, it’s important to understand the mental model that explains how AI coding companions fit into a data engineering workflow. 10 © Manning Publications Co. To comment go to liveBook Licensed to Ibrahim Mohammed Mohammed <ibrahim@dotnetebusiness.com>
Page
15
At the center of this model is you, the data engineer. On either side of you are two distinct but interconnected environments: your AI coding companion (such as ChatGPT), where you input prompts and receive natural-language responses, including generated code or suggestions; and your coding environment (such as Jupyter, VS Code, or pgAdmin), where you paste that code, execute it, and interact with real-world systems like databases, files, APIs, or environment variables. Figure 2.1 The AI coding companion mental model: You, the data engineer, interact with a coding companion via prompts and responses, then test and execute code within a separate coding environment. This separation reinforces how AI generates code and supports learning prompt engineering This separation is intentional. While emerging tools are starting to blend these experiences —embedding AI directly into IDEs—the boundaries are still useful. Keeping your companion and your coding workspace separate helps you observe how prompts are interpreted by the model, learn how LLMs reason and generate responses, and identify where AI may hallucinate or misunderstand your intent. As of this writing, many commercial tools, such as GitHub Copilot, Cursor, and WindSurf, are blurring the line between assistant and IDE. These tools can be powerful, but for foundational learning, they often hide the underlying process. It’s like following a recipe with all the ingredients pre-measured and prepped—you might get a good meal, but you won’t learn how to chop, season, or adjust flavors on your own. For this reason, in the early chapters of this book, we intentionally keep the companion experience and the execution environment separate. This helps you learn how to design better prompts, evaluate AI-generated code before running it, and form mental models of what the LLM "understands." 11 © Manning Publications Co. To comment go to liveBook Licensed to Ibrahim Mohammed Mohammed <ibrahim@dotnetebusiness.com>
Page
16
Later in the book, we’ll graduate to embedding LLMs into the environment itself using tools like the OpenAI API. But first, we must understand the prompt-response dance. That’s where the real magic lies—and this mental model will guide you through it. 2.2 Advantages of Using an AI/LLM Coding Companion Incorporating LLMs into your coding workflow provides a range of significant benefits, especially for tasks that demand precision and efficiency. While basic tasks like generating simple SQL queries or Python functions can be handled manually, LLMs truly shine when the complexity increases. The more intricate the code, the greater the need for rapid iteration, error reduction, and refined logic—areas where AI companions excel. One of their most powerful advantages is the ability to support an iterative feedback loop: you can revise prompts based on output, gradually steering the model toward a more accurate or elegant solution with each pass. 2.2.1 Rapid Code Generation for Data Engineering Tasks AI coding companions can quickly generate code for complex tasks, such as nested loops, API integrations, multi-step transformations, or conditional data processing, allowing engineers to move beyond boilerplate coding. In these cases, the AI can handle complex logical patterns, freeing up engineers to focus on the higher-level architecture of their projects. 12 © Manning Publications Co. To comment go to liveBook Licensed to Ibrahim Mohammed Mohammed <ibrahim@dotnetebusiness.com>
Page
17
Figure 2.2 Reading from bottom to top, this timeline compares the traditional manual steps (left) versus an AI- assisted workflow (right) for API data extraction. The "Without AI" column illustrates the cumulative time and effort required to manually code each part of the task. In contrast, the "With AI" column shows how a well- structured prompt and a few refinements can significantly compress the workflow. 13 © Manning Publications Co. To comment go to liveBook Licensed to Ibrahim Mohammed Mohammed <ibrahim@dotnetebusiness.com>
Page
18
EXAMPLE: PROCESSING NESTED DATA STRUCTURES When working with nested JSON data, one of the biggest challenges is transforming it into a structured format that’s usable for analysis. For example, imagine a dataset of customer orders, where each order includes a list of products. Each product has a description field with details like name, brand, and color. Our goal is to convert this JSON into a product_order DataFrame. A DataFrame is a tabular data structure used in Python, especially with the pandas library, that allows for powerful filtering, transformation, and aggregation. In this case, each row will represent a single product along with its associated order information Additionally, the extracted data must include separate columns for the product name, brand, and color, which are to be derived from the product description using regular expressions. Furthermore, the price of each product must be adjusted based on the order's status: a 20% tax for "completed" orders and a 10% tax for "pending" orders. Orders with the status "canceled" should be excluded from the output entirely. For example, given the following input JSON: The resulting normalized table should resemble Table 2.1: Table 2.1 Example DataFrame order_id status product_name brand color price quantity price_with_tax 1 completed Air Max Nike Red 120 1 144 1 completed Ultraboost Adidas Black 150 2 180 2 pending Speedcat Puma White 90 3 99 { "order_id": 1, "status": "completed", "products": [ {"description": "Nike Air Max - Red", "price": 120.00, "quantity": 1}, {"description": "Adidas Ultraboost - Black", "price": 150.00, "quantity": 2} ] }, { "order_id": 2, "status": "pending", "products": [ {"description": "Puma Speedcat - White", "price": 90.00, "quantity": 3} ] }, { "order_id": 3, "status": "canceled", "products": [ {"description": "Reebok Classic - Blue", "price": 100.00, "quantity": 1} ] } ] 14 © Manning Publications Co. To comment go to liveBook Licensed to Ibrahim Mohammed Mohammed <ibrahim@dotnetebusiness.com>
Page
19
When working with nested JSON data, such as an order object that includes a list of products, it's often necessary to "normalize" the structure into a flat table format. This means expanding each product in the products array into its own row while repeating shared values like order_id and status for each one. For example, in the JSON snippet above, the order_id and status apply to the entire order, while products contains multiple entries with their own description, price, and quantity. In the normalized table, each product becomes a separate row, with columns extracted from the description field (e.g., product_name, brand, and color), along with price, quantity, and even a computed price_with_tax column. This transformation makes it easier to analyze and query the data using tools like SQL or pandas, where each row represents a single, fully detailed product entry tied back to its original order. COMPLEXITY AND TESTING CHALLENGES Manually implementing this solution introduces several layers of complexity. Flattening the nested JSON into rows while maintaining relationships between orders and products requires precise traversal logic. The additional step of extracting product details from the description field with regular expressions demands crafting patterns robust enough to handle inconsistencies in the input. Moreover, even though this example applies a simple adjustment for tax rates, scaling this logic to handle additional transformations (e.g., discounts, status-specific rules) can quickly become cumbersome. Ensuring correctness across all edge cases requires extensive testing. These challenges highlight how much effort and time would be needed for manual development and debugging. LEVERAGING AI FOR A SIMPLIFIED SOLUTION To streamline this process, we can use ChatGPT, specifically ChatGPT-4 from OpenAI. This tool provides a conversational interface where you can describe your problem, include sample data, and receive code solutions tailored to your requirements. The advantage of a conversational interface lies in its flexibility: you can refine the prompt, request modifications, or add new requirements without rewriting the code yourself. Here’s how you can frame your prompt when using ChatGPT: 15 © Manning Publications Co. To comment go to liveBook Licensed to Ibrahim Mohammed Mohammed <ibrahim@dotnetebusiness.com>
Page
20
Prompt: "Transform this JSON into a pandas DataFrame where each row represents a product. Include columns for order_id, status, product_name, brand, color, price, quantity, and price_with_tax. Extract product_name, brand, and color from the 'description' field using regex. Apply a tax rate of 20% for completed orders and 10% for pending orders. Skip canceled orders. Response: [{ "order_id": 1, "status": "completed", "products": [ {"description": "Nike Air Max - Red", "price": 120.00, "quantity": 1}, {"description": "Adidas Ultraboost - Black", "price": 150.00, "quantity": 2} ] }, { "order_id": 2, "status": "pending", "products": [ {"description": "Puma Speedcat - White", "price": 90.00, "quantity": 3} ] }, { "order_id": 3, "status": "canceled", "products": [ {"description": "Reebok Classic - Blue", "price": 100.00, "quantity": 1} ] } ] " 16 © Manning Publications Co. To comment go to liveBook Licensed to Ibrahim Mohammed Mohammed <ibrahim@dotnetebusiness.com>