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 :: df col to dict 
Python :: _getfullpathname: path should be string, bytes or os.PathLike, not list 
Python :: pygame.rect 
Python :: slicing string in python 
Python :: how to change column name in pandas 
Python :: grid search cv 
Python :: python zeros to nan 
Python :: Get Current Date using today method 
Python :: how to resize tkinter window 
Python :: how to save the model in python 
Python :: urllib urlretrieve python 3 
Python :: convert price to float python 
Python :: web crawler using python 
Python :: drop column pandas 
Python :: subprocess.check_output python 
Python :: two for loops in list comprehension 
Python :: isdigit in python 
Python :: seaborn pairplot 
Python :: how do i convert a list to a string in python 
Python :: http server 
Python :: tensorflow_version 
Python :: python 2 deprecated 
Python :: check if a the time is 24 hours older python 
Python :: python nested list comprehension 
Python :: pytorch optimizer change learning rate 
Python :: yahoo finance api python 
Python :: migrate data django 
Python :: python dict remove key 
Python :: numpy stack arrays vertically 
Python :: how to use turtle in python in python 3.9 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =