Plotting timeseries from a csv file using matplotlib

Denis McMahon denismfmcmahon at gmail.com
Fri Nov 13 09:32:38 EST 2015


On Thu, 12 Nov 2015 21:27:58 -0800, Karthik Sharma wrote:

> I have some csv data in the following format. ......

Does the following idea help?

Create a key from the key fields, remove the key fields from the row dic 
(so now it's a dic of just the data fields), and save that in the 
plotdata dict keyed by the key.

import csv

keybits = ["Ln","Dr","Tag","Lab"]

plotdata = {}

with open("lab.csv", 'r') as fin:
    reader = csv.DictReader(fin)
    for row in reader:
        key = tuple([row[k] for k in keybits])
        for k in keybits:
            del row[k]
        plotdata[key] = row

This generates a dictionary (plotdata) keyed by the key tuples where the 
value for each key is a dictionary of 0:0n : value

-- 
Denis McMahon, denismfmcmahon at gmail.com



More information about the Python-list mailing list