从csv中包含空格的列制作数字列表

时间:2019-07-12 20:52:37

标签: python

我正在练习Python,并且想简单地编译csv文件(即CC语句)中的“ Credit”列。该列同时包含数字和空格,但是从列表中打印出来是完全错误的。

Here is a picture of the sample of my CC statement that I'm working with.

with open(filename) as f:
    FinancesReader = csv.reader(f)
    header_row = next(FinancesReader)

    TotalCredit = []
    for row in FinancesReader:
        TotalCredit1 = (row[4])
        for value in TotalCredit1:
            if not value.isdecimal():
                TotalCredit.append(TotalCredit1)

输出:

[' 500.00 ', ' 500.00 ', ' 500.00 ', ' 344.00 ', ' 344.00 ', ' 344.00 ']

这是我得到的结果,但是语句中的每个“ 500.00”和“ 344.00”数字只有一个功劳。我不确定为什么要重复结果。

我认为这是因为我有两个“ for”循环,但我不确定。

0 个答案:

没有答案