How to do a simple cross column classification in Python (Pandas/Numpy)? -



How to do a simple cross column classification in Python (Pandas/Numpy)? -

i have dataframe

a = pd.dataframe([['cat_1', 'cat_1', 'cat_2'], ['cat_1', 'cat_2', 'cat_2'], ['cat_2', 'cat_2', 'cat_2'], ['cat_1', 'cat_1', 'cat_1'], ['cat_2', 'cat_1', 'cat_2']], columns=['a', 'b', 'c'], index=[1, 2, 3, 4, 5])

i count , summarize in table different occurring combinations of pairs between two. in example, columns , b, output.

b 'cat_1' 'cat_2' 'cat_1' 2 1 'cat_2' 1 1

i thought bay using, , seems result, don't think appropriated way it....

a.groupby(['a', 'b']).agg([len]) out[126]: c len b cat_1 cat_1 2 cat_2 1 cat_2 cat_1 1 cat_2 1

thanks

this is pd.crosstab (short "cross-tabulation", think) does:

pd.crosstab(a['a'], a['b']) out[5]: b cat_1 cat_2 cat_1 2 1 cat_2 1 1

python numpy pandas grouping dataframes

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -