From the course: Advanced Python: Top Tools for Data Science and Engineering
Unlock this course with a free trial
Join today to access over 24,900 courses taught by industry experts.
Working with Polars data
From the course: Advanced Python: Top Tools for Data Science and Engineering
Working with Polars data
- [Instructor] Just like with Pandas, Polars can also perform a variety of data operations on data frames, such as sorting, grouping, and filtering. In this example, we'll see how to perform each one of these operations, and I'll be using the sales_data.csv file just as I did in the Pandas example. Alright, so let's open up our PolarsData.py file, and you can see I'm already importing the sales_data.csv file. So let's start with sorting operations first. To sort a Polars data frame, I can use the sort function and that returns a new data frame, so I'm going to write sorted_df = and then I'm going to use the sort function and I'm going to specify the column I want to sort on, so that will be SalesAmount in this example, and then I'll specify descending=True and then we'll print out the sorted data frame. Alright, let's go ahead and try that. Okay, that seems to have worked. We've got sales amount descending. I can also sort on multiple columns. So to do that, I just need to supply a…