Here is a sample of the csv data:
Timestamp,Systolic,Diastolic,Pulse
201711051037,135,81,62
201711061614,121,74,60
201711150922,129,74,70
201711170901,135,80,65
I am using Python 3.6.8 and this script to create a dict:
from csv import DictReader as dict_reader
d = dict()
with open(CSV_FILE, 'r') as csvfile:
reader = dict_reader(csvfile)
ts, sy, dia, p = next(reader)
for r in reader:
d[r[ts]] = int(r[sy]), int(r[dia]), int(r[p])
The result is:
{'201711051037': (135, 81, 62), '201711061614': (121, 74, 60), '201711150922': (129, 74, 70), '201711170901': (135, 80, 65)}
I would like to convert the result into a form that can be used with Matplotlib plot. Possibly something like:
Timestamp = [201711051037, 201711061614, 201711150922, 201711170901]
Systolic = [135, 121, 129, 135]
Diastolic = [81, 74, 74, 80]
Pulse = [62, 60, 70, 65]
In order to create a line plot with Matplotlib and use fills and other features, I believe the data needs to be in separate lists. I have tried different things like:
index = list(d.keys())
data = list(d.values())
sy = [data[i][j] for i in data for j in data]
And also looked at these similar questions:
Make dicts read from a csv file ordered dicts
Python matplotlib plot dict with multiple values
Plotting a dictionary with multiple values per key
However, I am stuck at this point. Any hints or directions would be greatly appreciated. Thanks.
