Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas groupby and show specific column

In [11]: df.groupby(['Country', 'Item_Code'])[["Y1961", "Y1962", "Y1963"]].sum()
Out[11]:
                       Y1961  Y1962  Y1963
Country     Item_Code
Afghanistan 15            10     20     30
            25            10     20     30
Angola      15            30     40     50
            25            30     40     50
Comment

Pandas GroupBy and keep Columns

In [20]:
df.groupby(['Name','Type','ID']).count().reset_index()

Out[20]:
    Name   Type  ID  Count
0  Book1  ebook   1      2
1  Book2  paper   2      2
2  Book3  paper   3      1
Comment

PREVIOUS NEXT
Code Example
Python :: np.random.choice replace 
Python :: python inspect module 
Python :: python file io 
Python :: mute command discord.py 
Python :: how to add a key in python dictionary 
Python :: pandas add time to datetime 
Python :: regular expression in python 
Python :: python sort array by key 
Python :: how to make an error message in python 
Python :: python parse xml string 
Python :: python add column with constant value 
Python :: bounding box in pyplot 
Python :: python how to draw a rectangle 
Python :: flask socketio send 
Python :: convert files to jpeg 
Python :: sum 2d array in python 
Python :: python round function example 
Python :: python hex 
Python :: min max python 
Python :: how to convert int in python 
Python :: rabbitmq python 
Python :: python tokens 
Python :: tri python 
Python :: reading an image using opencv library 
Python :: python beautifulsoup get attibute 
Python :: best python programs 
Python :: indent python 
Python :: mro in python 
Python :: how to add items in list in python at specific position 
Python :: how to clear combobox tkinter 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =