Querying Your Dataset
So, how does this work? First, look at the query itself. This evaluates the
'year_id' column and compares each value to
2010. If the value is greater, the result is
False if it is less or equal.
Then all of the results are returned in a
Series. Note that this
Series has all 126,314 rows in the
DataFrame. However, if you query the
DataFrame, it will only return the rows where a
True value exists in the
First of all, verify this with the
.info() method. It seems that only 5,400 games have notes. How can you weed out the games with no notes? The
notes column will be null for the 120,000 or so games that have no notes.
Therefore, you can use the
.notnull() method to test the
'notes' column. Just like the previous demo, this returns a
Series of bools, and you can use this to query the entire
DataFrame to include just the data you want.
object data type? It’s how strings are stored in the
DataFrame. You can access the
.str attribute of a
object column and call string methods to filter the column on the values. For example, the
'fran_id' column stores the name of the franchise of the team.
Become a Member to join the conversation.