Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas dataframe crosstab

pd.crosstab(index = df['column1'], columns = df['column2'])
Comment

pandas crosstab

pd.crosstab(index=diamonds['cut'],
            columns=diamonds['color'],
            values=diamonds['price'],
            aggfunc=np.mean).round(0)
Comment

pandas .crosstab

>>> 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)
>>> pd.crosstab(a, [b, c], rownames=['a'], colnames=['b', 'c'])
b   one        two
c   dull shiny dull shiny
a
bar    1     2    1     0
foo    2     2    1     2
Comment

PREVIOUS NEXT
Code Example
Python :: pick a random number from a list in python 
Python :: python remove suffix 
Python :: get page title by python bs4 
Python :: SystemError: tile cannot extend outside image 
Python :: change tkinter app icon 
Python :: github python projects for beginners 
Python :: reshape wide to long in pandas 
Python :: 3 dimensional array numpy 
Python :: odd or even python 
Python :: how to add window background in pyqt5 
Python :: python numpy array size of n 
Python :: unittest skip 
Python :: python 3 f string float format 
Python :: python except print error type 
Python :: how to read multiple csv file from different directory in python 
Python :: how to convert timestamp to date in python 
Python :: python custom sort 
Python :: python print datetime 
Python :: git help 
Python :: drop first two rows pandas 
Python :: import file from parent directory python 
Python :: numpy weighted average 
Python :: sort an array python 
Python :: isinstance python 
Python :: how to put a image in flask 
Python :: pyspark print a column 
Python :: Play Audio File In Background Python 
Python :: python iterate files 
Python :: python how to add up all numbers in a list 
Python :: python cocktail sort 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =