0

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?

2 Answers 2

9

Use the Python csv module.

Sign up to request clarification or add additional context in comments.

1 Comment

my delimiter is ' how do I use the delimiter= then?
7
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

3 Comments

an error appears saying that there's no such file as data.csv
@wildfire: When using this code, perhaps you should include the actual name for your actual .csv file in your actual working directory.
@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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.