python csv文件频率计数器

2024-06-25 23:18:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我有csv文件,其中包含id名称和摘要以及一些细菌名称。我要找出细菌的频率(Bac1,Bac2…)在抽象列中,并将其保存到具有列ID、Date和

我的文件csv示例:

ID  Date    Abstract                  Bac1      Bac2    Bac3
            research of the 
            vegetative organs 
            of the fendleri , 

3045 2018   cytoplasmatic hybrid 
            in vitro plants 
            containing the Brassicax

3046 2018   chloroplasts had been 
            conducted in comparison 
            to the parental forms.

3047 2018   It was found, that the
            anatomical structure 
            of the cybrid                   

Tags: 文件ofcsvthein名称abstractid
1条回答
网友
1楼 · 发布于 2024-06-25 23:18:48

你可以用下面这样的东西

with open(filename.csv, 'r') as f:
  for line in f:
    words=line.split(',')
    bac1_count=words[2].count(bac1)
    bac2_count=words[2].count(bac1)
    bac3_count=words[2].count(bac1)
    words.append(bac1_count, bac2_count, bac3_count)
    print(','.join(words))    

相关问题 更多 >