开发者

Extracting data from a CSV file in Python

I just got my data and it is given to me as a csv file.

It looks like this in data studio(where the file was taken).

Counts  frequency
300     1
302     5
303     7

Excel can't handle the computa开发者_如何学Gotions so that's why I'm trying to load it in python(it has scipy :D).

I want to load the data in an array:

Counts = [300, 302, 303]
frequency = [1, 5, 7]

How will I code this?


Use the Python csv module.


import csv

counts = []
frequencies = []

for d in csv.DictReader(open('yourfile.csv'), delimiter='\t'):
    counts.append(int(d['Counts']))
    frequencies.append(int(d['frequency']))

print 'Counts = ', counts
print 'frequency = ', frequencies
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜