October 2017
Intermediate to advanced
532 pages
16h 10m
English
The final result of this recipe is a DataFrame with MultiIndex columns. Using this DataFrame, it is possible to select just the crime or traffic accidents separately. The xs method allows you to select a single value from any index level. Let's see an example where we select only the section of data dealing with traffic:
>>> cr_final.xs('IS_TRAFFIC', axis='columns', level=0).head()

This is referred to as taking a cross section in pandas. We must use the axis and level parameters to specifically denote where our value is located. Let's use xs again to select only data from 2016, which is in a different level:
>>> cr_final.xs(2016, ...
Read now
Unlock full access