pandas crosstab

Solutions on MaxInterview for pandas crosstab by the best coders in the world

showing results for - "pandas crosstab"
Victor
16 Oct 2020
1>>> a = np.array(["foo", "foo", "foo", "foo", "bar", "bar",
2...               "bar", "bar", "foo", "foo", "foo"], dtype=object)
3>>> b = np.array(["one", "one", "one", "two", "one", "one",
4...               "one", "two", "two", "two", "one"], dtype=object)
5>>> c = np.array(["dull", "dull", "shiny", "dull", "dull", "shiny",
6...               "shiny", "dull", "shiny", "shiny", "shiny"],
7...              dtype=object)
8>>> pd.crosstab(a, [b, c], rownames=['a'], colnames=['b', 'c'])
9b   one        two
10c   dull shiny dull shiny
11a
12bar    1     2    1     0
13foo    2     2    1     2
14