Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python Pandas pivot on bin

df['bin'] = pd.cut(df.age, [0,4,9,14])

pvtdf = df.pivot_table(index='type', columns=['bin'], values='days', 
                       aggfunc=('count', 'sum')).fillna(0)

#       count                   sum               
# bin  (0, 4] (4, 9] (9, 14] (0, 4] (4, 9] (9, 14]
# type                                            
# a       2.0    0.0     1.0    6.0    0.0     1.0
# b       3.0    0.0     0.0    9.0    0.0     0.0
# c       0.0    1.0     0.0    0.0    1.0     0.0
# d       0.0    1.0     0.0    0.0    4.0     0.0
# e       0.0    0.0     1.0    0.0    0.0     2.0
# f       0.0    1.0     0.0    0.0    0.0     0.0
Comment

PREVIOUS NEXT
Code Example
Python :: python implode list 
Python :: how to open cmd at specific location usng python 
Python :: python convert 1 to 01 
Python :: pandas split dataframe to train and test 
Python :: python series sort 
Python :: python append to file 
Python :: python cv2 resize keep aspect ratio 
Python :: python tkinter listbox click event 
Python :: python how to get html code from url 
Python :: python suppress exponential notation 
Python :: pandas dataframe hist title 
Python :: pandas dataframe column rename 
Python :: equivalent of ament_index_python in noetic 
Python :: python return right operand if left is falsy 
Python :: download maninder in python gui 
Python :: how to increase and decrease volume of speakers using python 
Python :: python wget anaconda 
Python :: reverse one hot encoding python numpy 
Python :: selenium iframe python 
Python :: no such table: django_session 
Python :: override the text in buttons django admin 
Python :: quamtum criciut python 
Python :: find record in mongodb with mongodb object id python 
Python :: enumurate in python 
Python :: 2 d array in python with zeroes 
Python :: convert from object to integer python 
Python :: How to Add a Progress Bar into Pandas Apply 
Python :: pandas decimal places 
Python :: pandas dataframe aggregations 
Python :: binning data dataframe, faire classe statistique dataframe 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =