crosstab

Groupby value counts on the dataframe pandas

Groupby value counts on the dataframe pandas Question: I have the following dataframe: df = pd.DataFrame([ (1, 1, ‘term1’), (1, 2, ‘term2’), (1, 1, ‘term1’), (1, 1, ‘term2’), (2, 2, ‘term3’), (2, 3, ‘term1’), (2, 2, ‘term1’) ], columns=[‘id’, ‘group’, ‘term’]) I want to group it by id and group and calculate the number of …

Total answers: 6

How to make a pandas crosstab with percentages?

How to make a pandas crosstab with percentages? Question: Given a dataframe with different categorical variables, how do I return a cross-tabulation with percentages instead of frequencies? df = pd.DataFrame({‘A’ : [‘one’, ‘one’, ‘two’, ‘three’] * 6, ‘B’ : [‘A’, ‘B’, ‘C’] * 8, ‘C’ : [‘foo’, ‘foo’, ‘foo’, ‘bar’, ‘bar’, ‘bar’] * 4, ‘D’ …

Total answers: 6