Introduction to ETL Pipelines for Data Scientists

Learn the basics of data engineering to improve your ML models.

January 13, 2025 · ETL

Introduction

It is not news that developing Machine Learning algorithms requires data, often a lot of data. Collecting this data is not trivial, in fact, it is one of the most relevant and difficult parts of the entire workflow. When the data is not good, the algorithms trained on it will not be good either.

For example, recently, I started working on developing a model in an open-science manner for the European Space Agency for fine-tuning an LLM on data concerning earth observation and earth science. The whole thing is very exciting, but where do I get the data from?

In this article, we will look at some data engineering basics for developing a so-called ETL pipeline.

I run the scripts of this article using Deepnote: a cloud-based notebook that’s great for collaborative data science projects and prototyping.

What is the problem?

In data engineering, when we talk about pipelines, we basically talk about moving data from one place to another. In the case of training an LLM, we probably want to scrap text from various sources, such as Wikipedia, open books, datasets on hugging-face, etc. All these data, though are in different places and all have different formats, so the task starts to get difficult.

ETL pipeline (Image by Author)

A very popular type of pipeline when dealing with data is called ETL which stands for extract, transform, load. ETL pipelines precisely deal with extracting data from somewhere (such as Wikipedia), transforming data, for example, from HTML pages into text files, and loading, i.e., loading these files to a place where they are easily retrievable, for example, using MySQL or MongoDB.

Extract

Let’s look at a simple example where we need code to extract information from files of different types using Pandas. These examples are trivial; the main purpose is to understand the workflow.

Let’s suppose to have data in the following formats:

id,name,age
1,Alice,30
2,Bob,25
3,Charlie,35
[
    {"id": 1, "name": "Alice", "age": 30},
    {"id": 2, "name": "Bob", "age": 25},
    {"id": 3, "name": "Charlie", "age": 35}
]
<data>
    <person>
        <id>1</id>
        <name>Alice</name>
        <age>30</age>
    </person>
    <person>
        <id>2</id>
        <name>Bob</name>
        <age>25</age>
    </person>
    <person>
        <id>3</id>
        <name>Charlie</name>
        <age>35</age>
    </person>
</data>
id,name,age
1,Alice,30
2,Bob,25
3,Charlie,35

In this case simple pandas-based functions that extract this data are as follows:

In this case, we can do everything on our local machine, but in real projects, we work with large amounts of data so we have to manage a distributed storage system using tools like Hadoop.

Apache HadoopThis is a release of Apache Hadoop 3.3 line. It contains 117 bug fixes, improvements and enhancements since 3.3.5…hadoop.apache.orghadoop.apache.org

Transform

The second step after extracting the data is to transform them. In the context of data science, this means turning them in a way to be ready for training a Machine Learning algorithm. So we may combine the data, clean it, remove outliers remove duplicates and more. It is often said that a data scientist spends about 80% of his time collecting and arranging data. From my experience, I have seen that working on data quality can help you improve the outcome of a model much more than refining the model itself. In the picture below are some of the steps you can take when working to transform and improve the quality of the collected data.

Transforming techniques (Image by Author)

If you have experience with data science projects the steps you see in the picture will be very familiar to you. Otherwise, a suggestion I will give you to practice is to solve challenges you find on Kaggle. After you have tried your best to implement these steps to optimize the accuracy of your algorithm you can also see other people’s implementation of the same challenge, this will help you a lot

Kaggle Challenges:

Let us now briefly look at how to approach these steps.

Detect and exclude outliers in a pandas DataFrameI have a pandas dataframe with few columns. Now I know that certain rows are outliers based on a certain column value…stackoverflow.comstackoverflow.com Learn Feature Engineering TutorialsBetter features make better models. Discover how to get the most out of your data.www.kaggle.comkaggle.com

Load

Once the data has been transformed, we have to save it somewhere otherwise, the work done will be lost. There are various mechanisms for saving data, such as a relational database if we have structured data, or NoSQL DB for unstructured data.

Sometimes if the data is not very much we could also simply use a CSV file.

In this table, you will find a list of the most used solutions sorted by their trendiness.

src: https://db-engines.com/en/ranking
Source ↗
DB-Engines RankingThe DB-Engines Ranking shows the popularity of 421 database management systemsdb-engines.comdb-engines.com

Conclusions

In this article we learned the basics of building an ETL pipeline: extraction of data in various formats via Pandas, transforming the same in a manner that added value, and then loading it into appropriate storage solutions. Good ETL processes are at the heart of proper and correct data analysis and have enormous consequences on any machine learning model’s performance. With those skills, you can be confident that your data is well-prepared and ready to serve up valuable insights.

If you are interested in this article, follow me on Medium! 😁

💼 Linkedin ️| 🐦 X (Twitter) | 💻 Website

This article has been published on Towards AI