In [1]:
import numpy
import pandas as pd
from pandas import Series, DataFrame
def readD(val):
if 'C' in val:
return numpy.nan
return val
df = pd.read_csv('/Users/John/Dropbox/LLU/ROP/Pulse Ox/ROP013PO.csv',
parse_dates={'timestamp': ['Date','Time']},
index_col='timestamp',
usecols=['Date', 'Time', 'SpO2', 'PR', 'PI', 'Exceptions'],
na_values=['0'],
converters={'Exceptions': readD}
)
In [2]:
df[27:33]
Out[2]:
In [3]:
lst1 = df.Exceptions[27:33]
lst1
Out[3]:
In [ ]:
yay = df.PI
'''
for i in lst1:
if 'C' not in i:
avgPI = df.PI.mean
print avgPI
>>> rpt[rpt['STK_ID'].str.contains(r'^600[0-9]{3}$')] # ^ means start of string
... STK_ID ... # [0-9]{3} means any three digits
... '600809' ... # $ means end of string
'''
# str.contains()
#yay2 = df['Exceptions'].str.contains('C')
#yay2[27:33]
#this is me trying to figure out if I can edit the csv outside of read_csv
In [22]:
df_PI = df[df.loc[:, ['SpO2', 'PR', 'PI', 'Exceptions']].apply(pd.notnull).all(1)]
#if you can make string become 'N'
#http://stackoverflow.com/questions/17826001/skipping-rows-in-a-csv-file-using-python-pandas
In [23]:
df_PI
Out[23]:
In [21]:
PI = df.PI[1:3]
df.PI[1:5].std()
Out[21]:
In [ ]:
import matplotlib
matplotlib.style.use('ggplot')
df[1:5].plot()
In [24]:
import csv
from StringIO import StringIO
import textwrap
csv.register_dialect('escaped', escapechar='\\', doublequote=False, quoting=csv.QUOTE_NONE)
csv.register_dialect('singlequote', quotechar="'", quoting=csv.QUOTE_ALL)
# Generate sample data for all known dialects
sniffer = csv.Sniffer()
for name, expected, sample in samples:
print '\nDialect: "%s"\n' % name
dialect = sniffer.sniff(sample, delimiters=',\t')
reader = csv.reader(StringIO(sample), dialect=dialect)
for row in reader:
print row
In [ ]:
In [ ]: