如何循环和比较2个csv文件

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

好吧所以有些人可能以前看过这个代码,但我解释得非常糟糕。

这是使用中的csv文件:

菲尔1:

 Needie Seagoon 57      83  55  78      91  73  65  56          
    Eccles      98  91  80      66              77  78  48  77
    Bluebottle  61      88  80  60      45  52  91  85          
    Henry Crun  92      58  50  57      67  45  77  72          
    Minnie Bannister    51      97  52  53      68  58  70  69          
    Hercules Grytpype-Thynne        78  62  75      67              48  56  89  67
    Count Jim Moriarty  51      68  51  66      55  72  50  74          
    Major Dennis Bloodnok       54  47   59     48              66  58  53  83

档案2:

CITS1001    95
CITS1401    100
CITS1402    97
CITS2002    99
CITS2211    94
CITS2401    95
CITS3001    93
CITS3002    93
CITS3003    91
CITS3200    87
CITS3401    98
CITS3402    93
CITS3403    88

我想用分数来规范化。所以我想循环遍历file1 index [1]列。所以

57
(empty)
61
92
51
(empty)
51

并将每个分数除以CITS1001中的最高分95。另外你如何循环一个空字符串或值,给我一个错误,int()不是基数10:''

这是迄今为止我能做的最好的事情:

def normalise(students_file, units_list):
    file1 = open(students_file, 'r')
    data1 = file1.readlines()

    for line in data1:
        cell = line.split(",")
        if cell == "":
            line.next()
        else:
            stu_first = int(cell[1])
            answer = stu_first / 95
            print(answer)

所以units_list还没有添加,因为我似乎无法先通过students_file循环。我刚刚添加了95以查看列表中的答案。

注意:我没有使用模块练习atm,请不要说使用csv模块或熊猫,谢谢。

建议将不胜感激。

python-3.x
1个回答
0
投票

我认为python pandas值得研究。这是大熊猫的完美用例。

Compare two csv files with python pandas

© www.soinside.com 2019 - 2024. All rights reserved.