gpt4 book ai didi

python - 使用python计算表中某些id的值

转载 作者:太空宇宙 更新时间:2023-11-04 03:13:28 27 4
gpt4 key购买 nike

我有这样的数据

ID,"url","used_at","active_seconds"
d684cd5f0189ab49c391c2b7bcbac0cb,"vk.com/videos168693045?section=all",2016-03-01 10:18:45,4
d684cd5f0189ab49c391c2b7bcbac0cb,"vk.com",2016-03-01 10:18:49,2
d684cd5f0189ab49c391c2b7bcbac0cb,"vk.com/feed",2016-03-01 10:18:51,2
d684cd5f0189ab49c391c2b7bcbac0cb,"vk.com/audios291781172",2016-03-01 10:18:53,2
d684cd5f0189ab49c391c2b7bcbac0cb,"vk.com/audios291781172?q=Тимур%20Гатиятуллин%20%7C%20Честный%20-%20Улетай%20полная%20версия",2016-03-01 10:18:55,6
d684cd5f0189ab49c391c2b7bcbac0cb,"vk.com/audios291781172?q=Тимур%20ГатиятуллинЧестный%20-%20Улетай%20полная%20версия",2016-03-01 10:19:01,2
d684cd5f0189ab49c391c2b7bcbac0cb,"vk.com/audios291781172?q=Тимур%20Гатиятуллин%20Честный%20-%20Улетай%20полная%20версия",2016-03-01 10:19:03,4
d684cd5f0189ab49c391c2b7bcbac0cb,"vk.com/audios168693045?section=all",2016-03-01 10:19:07,2

我需要计算 url 中包含 audiosid。期望输出:

d684cd5f0189ab49c391c2b7bcbac0cb: 291781172 - 4, 168693045 - 1, etc

我不知道如何在 audio 之后获取 id 并计算它。

data = pd.read_csv("get_id.csv")
data_name = pd.read_excel("name.xlsx")
names_panel = data_name['Names']
urls = data['url']
ids = data['ID']
for url in urls:
if 'audios' in url:
print url

最佳答案

print pd.concat([df['ID'], df['url'].str.extract('(?P<count>audios)(?P<digit>\d+)')], axis=1).groupby(['ID', 'digit']).count()

count
ID digit
d684cd5f0189ab49c391c2b7bcbac0cb 168693045 1
291781172 4

关于python - 使用python计算表中某些id的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37157370/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com