首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >排列并查找列表中出现的最多的项目

排列并查找列表中出现的最多的项目
EN

Stack Overflow用户
提问于 2019-12-30 21:07:22
回答 2查看 52关注 0票数 0

代码语言:javascript
复制
Scott Logistics Corp
Transportation One LLC
Brothers Logistics Inc
Western Express Inc
Dart Advantage Logistics
Western Express Inc
Western Express Inc
Landstar Inway
Circle Logistics Inc
Rightway Logistics
Rightway Logistics
Rightway Logistics
Spike Freight Service
Rightway Logistics
Rightway Logistics
AMX Logistics
T A Services Inc Formerly Team America Inc
J & R Schugel/Super Service
NFI Logistics/NFI Transportation
Titanium Trucking Services/Titanium Logistics
Patterson Companies Inc
Arrive Logistics
Cavalry Logistics Llc
Landstar Ranger Inc
Landstar Ranger Inc
Logistic Dynamics Inc/Ldi Trucking Inc
US Xpress Inc
US Xpress Inc
XPO Logistics LLC
Bedrock Logistics
Transfix Inc
Convoy Inc
Choctaw Logistics Llc
Trekker Logistics LLC
Landstar Ranger Inc
MAG Carriers Llc/Mag Transportation Llc
Capital Logistics Group LLC/Clg Transportation
Capital Logistics Group LLC/Clg Transportation
Landstar Ranger Inc
XPO Logistics LLC

上面是公司名称的数据集,在相同的情况下,某个名字出现了一个,两个多于两个。我想要一个密码来安排他们。有些公司的名称出现得比一个公司多,但在不同的位置,如何将它们排列到一个位置?实际上我想数一数哪家公司在数据中出现得最多。如果有其他方法来找出哪个名字出现得最多,请告诉我。

EN

回答 2

Stack Overflow用户

发布于 2019-12-30 21:10:50

您可以从集合(python中的核心模块之一)使用Counter函数,您不需要安装它:

代码语言:javascript
复制
from collections import Counter
counts = Counter(your_list)
票数 2
EN

Stack Overflow用户

发布于 2019-12-30 21:29:03

你可以用潘达斯。

尝尝这个,

代码语言:javascript
复制
import pandas as pd

我为您提供的数据创建了一个文件,然后导入它:

代码语言:javascript
复制
df = pd.read_csv('company.txt', header=0)

文件看起来像这样,

代码语言:javascript
复制
 name
"Scott Logistics Corp"
"Transportation One LLC"
"Brothers Logistics Inc"
"Western Express Inc"
"Dart Advantage Logistics"
"Western Express Inc"
"Western Express Inc"
"Landstar Inway"
"Circle Logistics Inc"
....

然后,

像这样重复最多的名字,

代码语言:javascript
复制
print('**Name most repeated**')
print(df['name'].value_counts().idxmax())

获取重复该名称的次数。

代码语言:javascript
复制
print('**this many times**')
print(df['name'].value_counts().max())

对于您提供的数据,输出如下所示

代码语言:javascript
复制
**Name most repeated**
Rightway Logistics
**this many times**
5
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59536841

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档