bigframes.pandas.crosstab#
- bigframes.pandas.crosstab(index,columns,values=None,rownames=None,colnames=None,aggfunc=None,*,session:Session|None=None)→DataFrame[source]#
Compute a simple cross tabulation of two (or more) factors.
By default, computes a frequency table of the factors unless anarray of values and an aggregation function are passed.
- Examples:
>>>a=np.array(["foo","foo","foo","foo","bar","bar",..."bar","bar","foo","foo","foo"],dtype=object)>>>b=np.array(["one","one","one","two","one","one",..."one","two","two","two","one"],dtype=object)>>>c=np.array(["dull","dull","shiny","dull","dull","shiny",..."shiny","dull","shiny","shiny","shiny"],...dtype=object)>>>bpd.crosstab(a,[b,c],rownames=['a'],colnames=['b','c'])b one twoc dull shiny dull shinyabar 1 2 1 0foo 2 2 1 2[2 rows x 4 columns]
- Parameters:
index (array-like,Series, orlist ofarrays/Series) – Values to group by in the rows.
columns (array-like,Series, orlist ofarrays/Series) – Values to group by in the columns.
values (array-like,optional) – Array of values to aggregate according to the factors.Requiresaggfunc be specified.
rownames (sequence,default None) – If passed, must match number of row arrays passed.
colnames (sequence,default None) – If passed, must match number of column arrays passed.
aggfunc (function,optional) – If specified, requiresvalues be specified as well.
- Returns:
Cross tabulation of the data.
- Return type: