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 :: python crear dataframe 
Python :: geopandas geometry length 
Python :: fastapi upload file save 
Python :: how to make python code faster 
Python :: installation of uvicorn for fastapi 
Python :: how to cut image python 
Python :: not in python 
Python :: how to convert datetime to integer in python 
Python :: HUNGRY CHEF codechef 
Python :: django start app 
Python :: read part of file pandas 
Python :: Set value for particular cell in pandas DataFrame using index 
Python :: python run code at the same time 
Python :: change value in excel in python 
Python :: get key(s) for min value in dict python 
Python :: install os conda 
Python :: numpy array serialize to string 
Python :: merge pandas datasets 
Python :: django signals post_save not working 
Python :: python list of whole numbers 
Python :: installing private python packages from requirements.txt 
Python :: matplotlib larger chart 
Python :: histogram seaborn python 
Python :: calculate perimeter of rectangle in a class in python 
Python :: postgresql backup using python 
Python :: swapping variables in python 
Python :: discord.py get id of sent message 
Python :: seaborn color palette python 
Python :: Python How to get the keys in a dictionary? 
Python :: ubuntu 20.10 python 3.8 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =