Move from Excel to Python with Pandas Transcripts
Chapter: Data wrangling with Pandas
Lecture: Filtering by dates

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