课程: Hands-On Advanced Python: Data Engineering Basics

免费学习该课程!

今天就开通帐号,24,700 门业界名师课程任您挑!

Grouping data

Grouping data

- [Lecturer] In this example, we're going to take a look at how to organize data into groups. And we're going to do this by making use of the group by function that is included in the inner tools module from the Python Standard Library. So let's open up our grouping code and let's go ahead and give ourselves some more space to read. Alright, first, let's start by importing that function from itertools. I'm going to import group by. Alright, so now I can make use of that function. But before we see how to use group by to form data groups, let's take a look at how you would achieve this manually by using a regular dictionary. So you can see I already have some code here that gets all of the weather data for the days in 2022. And then scroll, down a little bit here, I'm using a default dictionary with a list type for each of the default values. And then on this line here I have some code that creates a sorted list of all of…

内容