From the course: Faster pandas
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Understanding the isin function
- [Instructor] Say you'd like to check if you have entries in your LOC files from forbidden IPs. The IPs are in logs.db, and the forbidden IP list, which are randomly generated, is in ips.txt.xz. Let's have a look. So ipython, and we're going to import pandas as pd, and to load the data from the database, we going to import sqlite3. We create the connection, so conn equal sqlite3.connect, to logs.db, and we're going to tell it to detect types equal sqlite3.PARSE_DECLTYPES. And then we say df is pd.read_sql, and you're going to do select everything from logs using the connection. And now we're going to load the forbidden IP list, so import lzma, and with lzma.open logs, it always cut to here, and with lzma.open, ips.txt.xz, and we say that we're going to read it in a textual format as fp. We say that ips are line.strip for line in fp. And if we look at the length, we have 100,000 forbidden IPs. First we're going to use the pandas isin method to check if a value in the origin column is…
Contents
-
-
-
-
-
(Locked)
The limitations of appending3m 28s
-
(Locked)
The limitations of object dtype2m 21s
-
(Locked)
The limitations of row iteration3m 18s
-
(Locked)
Understanding the isin function4m 39s
-
(Locked)
Parsing time once2m 42s
-
(Locked)
Challenge: Query a DataFrame1m 38s
-
(Locked)
Solution: Query a DataFrame1m 29s
-
(Locked)
-
-
-
-
-
-