Gravity M
Gravity M

Reputation: 1517

How to read a two digit numbers in CSV file and storying it in a list?

I am scanning a column in Python, which is full of integers. There are some double digit numbers.

d = []

for Column in ReadDataSourceFile: #ReadDataSourceFile works well. Its file open and delimiter
    if Column[1] == 'Something' and Column[0] == 'Somewhere':
        countFL += 1
        print Column[5]
        some = map(int, Column[5])
        d.extend(some)

print d

Here Column[5] is 1, 15, 23, 1, 4, 5. But the print displays [1, 1, 5, 2, 3, 1, 4, 5]

Upvotes: 0

Views: 415

Answers (2)

Niels
Niels

Reputation: 3

Your first output looks like a string Maybe this will work:

Column[5].split(',')

Upvotes: 0

furas
furas

Reputation: 142720

Probably some = map(int, Column[5]) split number on the digits

print map(int, '15')

[1, 5]

So print some to check it.

Maybe you need only some = int(Column[5])


EDIT: try

    print Column[5]
    some = int(Column[5])
    d.append(some)

Upvotes: 2

Related Questions