tags:

views:

173

answers:

2

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 computations 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?

+8  A: 

Use the Python csv module.

Daniel Roseman
+4  A: 
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
nosklo
an error appears saying that there's no such file as data.csv
wildfire
@wildfire: When using this code, perhaps you should include the actual name for your actual .csv file in your actual working directory.
S.Lott
@wildfire: of course you need to include the full path to the file on your system, instead of the example "yourfile.csv" I've put into the code.
nosklo