简体   繁体   中英

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

使用Python csv模块。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM