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]:
actionaction_typeindexMissing0lookupMissing5personalizeMissing0search_resultsMissing0AllMissing5dtype: 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"