Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何检查熊猫数据帧中每个唯一值的频率?_Python_Arrays_Pandas_Dataframe - Fatal编程技术网

Python 如何检查熊猫数据帧中每个唯一值的频率?

Python 如何检查熊猫数据帧中每个唯一值的频率?,python,arrays,pandas,dataframe,Python,Arrays,Pandas,Dataframe,如果我有一个2000的数据框,假设品牌有142个唯一值,我想计算每个唯一值的频率,从1到142。值应该动态变化 brand=clothes_z.brand_name brand.describe(include="all") unique_brand=brand.unique() brand.describe(include="all"),unique_brand from collections import Counter ll = [...your list of brands...

如果我有一个2000的数据框,假设品牌有142个唯一值,我想计算每个唯一值的频率,从1到142。值应该动态变化

brand=clothes_z.brand_name
brand.describe(include="all")
unique_brand=brand.unique()
brand.describe(include="all"),unique_brand
from collections import Counter


ll = [...your list of brands...]
c = Counter(ll)
# you can do whatever you want with your counted values
df = pd.DataFrame.from_dict(c, orient='index', columns=['counted'])
输出:

(count       2613
unique      142
 top       Mango
 freq         54
 Name: brand_name, dtype: object,
array(['Jack & Jones', 'TOM TAILOR DENIM', 'YOURTURN', 'Tommy Jeans',
        'Alessandro Zavetti', 'adidas Originals', 'Volcom', 'Pier One',
        'Superdry', 'G-Star', 'SIKSILK', 'Tommy Hilfiger', 'Karl Kani',
        'Alpha Industries', 'Farah', 'Nike Sportswear',
        'Calvin Klein Jeans', 'Champion', 'Hollister Co.', 'PULL&BEAR',
        'Nike Performance', 'Even&Odd', 'Stradivarius', 'Mango',
        'Champion Reverse Weave', 'Massimo Dutti', 'Selected Femme Petite',
        'NAF NAF', 'YAS', 'New Look', 'Missguided', 'Miss Selfridge',
        'Topshop', 'Miss Selfridge Petite', 'Guess', 'Esprit Collection',
        'Vero Moda', 'ONLY Petite', 'Selected Femme', 'ONLY', 'Dr.Denim',
        'Bershka', 'Vero Moda Petite', 'PULL & BEAR', 'New Look Petite',
        'JDY', 'Even & Odd', 'Vila', 'Lacoste', 'PS Paul Smith',
        'Redefined Rebel', 'Selected Homme', 'BOSS', 'Brave Soul', 'Mind',
        'Scotch & Soda', 'Only & Sons', 'The North Face',
        'Polo Ralph Lauren', 'Gym King', 'Selected Woman', 'Rich & Royal',
        'Rooms', 'Glamorous', 'Club L London', 'Zalando Essentials',
        'edc by Esprit', 'OYSHO', 'Oasis', 'Gina Tricot',
        'Glamorous Petite', 'Cortefiel', 'Missguided Petite',
        'Missguided Tall', 'River Island', 'INDICODE JEANS',
        'Kings Will Dream', 'Topman', 'Esprit', 'Diesel', 'Key Largo',
        'Mennace', 'Lee', "Levi's®", 'adidas Performance', 'jordan',
        'Jack & Jones PREMIUM', 'They', 'Springfield', 'Benetton', 'Fila',
        'Replay', 'Original Penguin', 'Kronstadt', 'Vans', 'Jordan',
        'Apart', 'New look', 'River island', 'Freequent', 'Mads Nørgaard',
        '4th & Reckless', 'Morgan', 'Honey punch', 'Anna Field Petite',
        'Noisy may', 'Pepe Jeans', 'Mavi', 'mint & berry', 'KIOMI', 'mbyM',
        'Escada Sport', 'Lost Ink', 'More & More', 'Coffee', 'GANT',
        'TWINTIP', 'MAMALICIOUS', 'Noisy May', 'Pieces', 'Rest',
        'Anna Field', 'Pinko', 'Forever New', 'ICHI', 'Seafolly', 'Object',
        'Freya', 'Wrangler', 'Cream', 'LTB', 'G-star', 'Dorothy Perkins',
        'Carhartt WIP', 'Betty & Co', 'GAP', 'ONLY Tall', 'Next', 'HUGO',
        'Violet by Mango', 'WEEKEND MaxMara', 'French Connection'],
       dtype=object))
因为它只显示Mango“54”的频率,因为它是最高频率,我想要每个值的频率,比如
Jack&Jones
TOM Tailer DENIM
YOURTURN
的频率等等。。。值应该是动态变化的。

您只需

brand=clothes_z.brand_name
brand.describe(include="all")
unique_brand=brand.unique()
brand.describe(include="all"),unique_brand
from collections import Counter


ll = [...your list of brands...]
c = Counter(ll)
# you can do whatever you want with your counted values
df = pd.DataFrame.from_dict(c, orient='index', columns=['counted'])
clothes_z.brand_name.value_counts()

这将列出唯一值,并为您提供该系列中每个元素的频率。

它返回集合。计数器以及如何将其转换为数据帧表只要了解如何执行计数器->数据帧。值得注意的是,集合是python中值得了解的强大模块。请看我最新的答案。谢谢你让我的生活变得轻松。。!我怎么能给你荣誉…?是的!都德,这也是一个简单的方法。我们能把这个系列转换成数据框并绘制可视化图吗