python csv文件频率计数

问题描述 投票:-2回答:1

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

我的文件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                   
python csv
1个回答
0
投票

你可以使用下面的东西

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))    
© www.soinside.com 2019 - 2024. All rights reserved.