Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #98728 > unrolled thread
| Started by | Karthik Sharma <karthik.sharma@gmail.com> |
|---|---|
| First post | 2015-11-12 21:27 -0800 |
| Last post | 2015-11-13 14:32 +0000 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.python
Plotting timeseries from a csv file using matplotlib Karthik Sharma <karthik.sharma@gmail.com> - 2015-11-12 21:27 -0800
Re: Plotting timeseries from a csv file using matplotlib Fabien <fabien.maussion@gmail.com> - 2015-11-13 12:51 +0100
Re: Plotting timeseries from a csv file using matplotlib Denis McMahon <denismfmcmahon@gmail.com> - 2015-11-13 14:32 +0000
| From | Karthik Sharma <karthik.sharma@gmail.com> |
|---|---|
| Date | 2015-11-12 21:27 -0800 |
| Subject | Plotting timeseries from a csv file using matplotlib |
| Message-ID | <d52cd13c-25e4-4393-8eff-6910c7394f17@googlegroups.com> |
I have some csv data in the following format.
Ln Dr Tag Lab 0:01 0:02 0:03 0:04 0:05 0:06 0:07 0:08 0:09
L0 St vT 4R 0 0 0 0 0 0 0 0 0
L2 Tx st 4R 8 8 8 8 8 8 8 8 8
L2 Tx ss 4R 1 1 9 6 1 0 0 6 7
I want to plot a timeseries graph using the columns (`Ln` , `Dr`, `Tg`,`Lab`) as the keys and the `0:0n ` field as values on a timeseries graph.I want all the timeseries to be plotted on a single timeseries?
I have the following code.
#!/usr/bin/env python
import matplotlib.pyplot as plt
import datetime
import numpy as np
import csv
import sys
with open("test.csv", 'r', newline='') as fin:
reader = csv.DictReader(fin)
for row in reader:
key = (row['Ln'], row['Dr'], row['Tg'],row['Lab'])
#code to extract the values and plot a timeseries.
~
How do I extract all the values in columns `0:0n` without induviduall specifying each one of them.
[toc] | [next] | [standalone]
| From | Fabien <fabien.maussion@gmail.com> |
|---|---|
| Date | 2015-11-13 12:51 +0100 |
| Message-ID | <n24isg$u08$1@speranza.aioe.org> |
| In reply to | #98728 |
On 11/13/2015 06:27 AM, Karthik Sharma wrote: > How do I extract all the values in columns Have a look at pandas: http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2015-11-13 14:32 +0000 |
| Message-ID | <n24sa6$f8n$2@dont-email.me> |
| In reply to | #98728 |
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@gmail.com
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web