Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Pandas pivot table

table = pd.pivot_table(df, values='D', index=['A', 'B'],
...                     columns=['C'], aggfunc=np.sum)
>>> table
C        large  small
A   B
bar one    4.0    5.0
    two    7.0    6.0
foo one    4.0    1.0
    two    NaN    6.0
Comment

Pandas pivot table

>>> emp.pivot_table(index='dept', columns='gender',                     values='salary', aggfunc='mean').round(-3)
Comment

pivot table pandas

# Simplest pivot table must have a dataframe
# and an index/list of index.
table = pd.pivot_table(df, index =['A', 'B'])
  
table
Comment

pandas pivot tables

>>> df = pd.DataFrame({'foo': ['one', 'one', 'one', 'two', 'two',
...                            'two'],
...                    'bar': ['A', 'B', 'C', 'A', 'B', 'C'],
...                    'baz': [1, 2, 3, 4, 5, 6],
...                    'zoo': ['x', 'y', 'z', 'q', 'w', 't']})
>>> df
    foo   bar  baz  zoo
0   one   A    1    x
1   one   B    2    y
2   one   C    3    z
3   two   A    4    q
4   two   B    5    w
5   two   C    6    t

>>> df.pivot(index='foo', columns='bar', values='baz')
bar  A   B   C
foo
one  1   2   3
two  4   5   6
Comment

pd df pivot

df.pivot(index='foo', columns='bar', values=['baz', 'zoo'])
Comment

df.pivot_table

df.pivot_table(values, index, aggfunc={'value_1': np.mean,'value_2': [min, max, np.mean]})
Comment

pd df pivot table

table = pd.pivot_table(df, values='D', index=['A', 'B'],
...                     columns=['C'], aggfunc=np.sum, fill_value=0)
Comment

pd df pivot table

table = pd.pivot_table(df, values='D', index=['A', 'B'],
...                     columns=['C'], aggfunc=np.sum)
Comment

pivot table pandas

df.pivot_table(index = [df.iloc[:,meet_friends], df.iloc[:,friendsgiving]])
Comment

pivot table pandas

df.pivot_table(['int_age'],index = [df.iloc[:,meet_friends], df.iloc[:,friendsgiving]])
Comment

pd df pivot

df.pivot(index='foo', columns='bar', values='baz')
Comment

pd df pivot

df.pivot(index="lev1", columns=["lev2", "lev3"],values="values")
Comment

PREVIOUS NEXT
Code Example
Python :: numpy unique axis 
Python :: var colors python 
Python :: Set path for another directory 
Python :: get hours from datetime.timedelta in python (Django) 
Python :: correlation meaning 
Python :: loading a webpage with aiohttp 
Python :: tkinter video 
Python :: python screeninfo 
Python :: run a for loop in python 
Python :: Maximize Difference codechef solution 
Python :: python lambda function use global variable 
Python :: python sympy symbols 
Python :: change every element of list python with map 
Python :: dict comprehension python 
Python :: How to make a function repeat itself a specifc amount of times python 
Python :: duplicate a list with for loop in python 
Python :: exception handling in tkinter 
Python :: get table wikipedia 
Python :: index start from 1 pandas 
Python :: cv2 videowriter python not working 
Python :: reverse range python 
Python :: pandas dataframe apply 
Python :: get value of 1 field in model django 
Python :: python web app 
Python :: odoo model 
Python :: python xmlrpc 
Python :: python generators 
Python :: seaborn orient 
Python :: how to add a 2d array to one dataframe colum 
Python :: python recursion example 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =