[PYTHON] GroupBy Note

Creating a DataFrame

qiita.rb


df = pd.DataFrame({'Animal': ['Falcon', 'Falcon',
                              'Parrot', 'Parrot','Parrot'],
                   'Max Speed': [380., 370., 24., 26.,27.],'Annimal_ID': [1, 1,2,2,2]})

df

image.png

Groupby Use when you want to process the same group.

average

qiita.rb


#Used when you want to do the same for Falcon and Parrot groups
df.groupby(['Animal']).mean()

image.png

Check / get the size

qiita.rb


#Check the size
df.groupby(['Animal']).size()

image.png

qiita.rb


#Get size
Falcon_num=df.groupby(['Animal']).size()['Falcon']
print(Falcon_num)

image.png

Data acquisition for a specific group

qiita.rb


#Get size
#Get data for a specific group
df.groupby(['Animal']).get_group('Falcon')

image.png

reference

GropuBy

Recommended Posts

GroupBy Note
Note
Note
Note
Django note 4
pyenv note
argparse note
Django Note 5
Note: Python
Ansible Note
Python note
Django Note 1
direnv note
Django note 3
Django note 2
[Note] RepresenterError
[Note] Image resizing
Python study note_002
Note: Python Decorator
Python programming note
[Python] Learning Note 1
Kinesis Firehose Note
Python study note_004
[Note] Regarding Tensorflow
[pandas] GroupBy Tips
Note: confusing nonlocal
Markdown Beginner's Note
PyData.Osaka Meetup # 2 Note
Python study note_003
Completely personal note
Flask's personal note # 2
Jupyter Study Note_002
TensFlow Preferences Note
[Note] openCV + python
Note about awk
Just a note
PyCharm Preferences Note
Note: List comprehension
Python beginner's note
Flask's personal note # 1
Jupyter Study Note_003
Jupyter Study Note_007
[Note] pandas unstack
Jupyter Study Note_005