[PYTHON] Note

import pandas as pd

#Pandas that count the number of occurrences of elements of each attribute.Returns a list of series
def count_attibute_value(df):
    list_of_attribute_series=[]
    columns_list = df.columns.values
    #attribute_num = len(columns_list)

    for attribute in columns_list:
        list_of_attribute_series.append(df[attribute].value_counts())
    return list_of_attribute_series


if __name__ == '__main__':
    #example
    df = pd.DataFrame({"item":[c for _ in range(5) for c in ["apple", "banana","orange"]],"rank":[chr(i%7+65) for i in range(15)]})
    l = count_attibute_value(df)
    print(df)
    print(l[0])
    print(l[1])

Recommended Posts

Note
Note
Note
Django note 4
pyenv note
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
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
AtCoder Beginner Contest 181 Note
[Note] Beginning of programming
[Note] future sentence ~ Python ~
[Note] File reading ~ Python ~
[Tips] My Pandas Note
AtCoder Beginner Contest 180 Note
ACL Beginner Contest Note
[Note] Random number creation?
Note about pointers (Go)
AtCoder Beginner Contest 182 Note
HJvanVeen's "Feature Engineering" Note
[Note] Selenium module introduced
[Note] Bluetooth keyboard emulation
MongoDB Java Driver Note
AtCoder Regular Contest 105 Note
[Note] PCA and t-SNE
What is JSON? .. [Note]
(Personal note) Sankey diagram
A note about __call__
Note to daemonize python
Note: python Skeleton Nya