Move from Excel to Python with Pandas Transcripts
Chapter: Data wrangling with Pandas
Lecture: Filtering by dates
0:00 weaken. Apply the same concepts when working with dates. So here we can filter on the Rose,
0:08 where the purchase date is greater than let's do rare than or equal to the first of December. And what is really nice about this is notice.
0:20 I'm just using a regular string for the date because Pandas knows that purchase date is
0:25 a date time. It converts this to a day tight format in dozen filtering for us as we would expect. So this is really handy when you're working with date
0:36 and times and trying to sub select certain portions of a date range similar to what we did with strings. We can combine these,
0:47 so let's define a purchase date.
1:05 So what we've done here is we've defined a purchase date where the month is equal to 11 and then we want to Onley look at books so we can combine those
1:16 again using the ampersand. And now this gives us all of our purchases of books
1:23 in the month of November. We can also use mathematical comparisons greater than less than
1:30 so. If we want to look at the quantity greater than 12 we can do that as well We could also do comparisons across columns.
1:43 So let's say we define something called men order sighs. It's five. So we now have a men order size. So let's assign that to a variable.
2:00 Call this small. And if we want to get a list of all the transactions that were small orders, we can tell there are 176 transactions.
2:19 And these are the companies and the products that they purchase, where they didn't get at least five units in their order.
2:29 Boolean filtering is going to give us a lot of flexibility as we structure our data It works on strings, works on numbers.
2:37 It works on dates. The other thing I wanted toe walk through quickly is another way. You can filter the data and I want to highlight it.
2:46 So you're aware of it. I'm not going to use a whole lot in the rest of the course I want you get used to using dot Lok for most of
2:54 your analysis, and then you can use this other option called Query a little bit later as you get some more experience.
3:01 So if we want to query our data frame, we can say, DF dot query. And if we want to understand quantity greater than 10 it's similar to the way low
3:15 quirks. And once again, this is just another functionality within pandas that can make
3:22 some of the chained assignments that you want to do is get more advanced easier. But I want to call it out now.
3:30 So you're aware of it and also mentioned that DOT Lok will do many of the
3:35 same things and will actually make it easier in the future when we want to assign
3:39 an update values. So that's why I focused on the dot lok approach and would
3:46 encourage you to do that in the beginning and then move to some of the other more sophisticated approaches as you get more experience.