Hello and welcome! Today, we're exploring practical data manipulation techniques in Python. We'll use Python lists to represent our data stream and perform projection, filtering, and aggregation. And here's the star of the show: our operations will be neatly packaged within a Python class! No mess, all clean code.
Data manipulation is akin to being a sculptor but for data. We chisel and shape our data to get the desired structure. Python lists are perfect for this, and our operations will be conveniently bundled inside a Python class. So, let's get our toolbox ready! Here's a simple Python class, DataStream, that will serve as our toolbox:
Our first stop is data projection. Think of it like capturing a photo of our desired features. Suppose we have data about people. If we're only interested in names and ages, we project our data to include just these details. We'll extend our DataStream class with a project_data method for this:
As you can see, we now have a new list with just the names and ages!
Next, we have data filtering, which is like cherry-picking our preferred data entries. We'll extend our DataStream class with a filter_data method that uses a "test" function to filter data:
With the filter method, our output is a list with only Bob’s data, as he's the only one who passes the 'age over 26' test.
