How To Filter A Crosstab Created In Pandas By A Specific Column
I have created a cross tabulation in pandas using: grouped_missing_analysis = pd.crosstab(clean_sessions.action_type, clean_sessions.action, margins=True).unstack() print(group
Solution 1:
Those are your indices and not columns, you need to pass labels to select the rows of interest.
You can pass slice(None)
for the first level and then a list for the second level:
In [102]:
grouped_missing_analysis.loc[slice(None), ['Missing', 'Unknown', 'Other']]
Out[102]:
action action_type
index Missing 0
lookup Missing 5
personalize Missing 0
search_results Missing 0
All Missing 5
dtype: int64
The docs give more detail on this style of indexing
Post a Comment for "How To Filter A Crosstab Created In Pandas By A Specific Column"