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]:
SpO2 PR PI Exceptions
timestamp
2015-10-13 14:58:20 87 168 0.4 NaN
2015-10-13 14:58:22 87 168 0.3 NaN
2015-10-13 14:58:24 87 168 0.3 8000
2015-10-13 14:58:26 87 168 0.3 8000
2015-10-13 14:58:28 87 170 0.4 8000
2015-10-13 14:58:30 87 170 0.4 8000

In [3]:
lst1 = df.Exceptions[27:33]

lst1


Out[3]:
timestamp
2015-10-13 14:58:20     NaN
2015-10-13 14:58:22     NaN
2015-10-13 14:58:24    8000
2015-10-13 14:58:26    8000
2015-10-13 14:58:28    8000
2015-10-13 14:58:30    8000
Name: Exceptions, dtype: object

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]:
SpO2 PR PI Exceptions
timestamp
2015-10-13 14:58:24 87 168 87 8000
2015-10-13 14:58:26 87 168 87 8000
2015-10-13 14:58:28 87 170 87 8000
2015-10-13 14:58:30 87 170 87 8000
2015-10-13 14:58:32 87 170 87 8000
2015-10-13 14:58:34 87 171 87 8000
2015-10-13 14:58:36 87 172 87 8000
2015-10-13 14:58:38 87 175 87 8000
2015-10-13 14:58:40 87 177 87 8000
2015-10-13 14:58:42 87 179 87 8000
2015-10-13 14:58:44 87 181 87 8000
2015-10-13 14:58:46 87 180 87 8000
2015-10-13 14:58:48 87 178 87 8000
2015-10-13 14:58:50 87 177 87 8000
2015-10-13 14:58:52 87 177 87 8000
2015-10-13 14:58:54 87 178 87 8000
2015-10-13 14:58:56 85 177 85 8000
2015-10-13 15:00:54 93 170 93 8000
2015-10-13 15:00:56 93 169 93 8000
2015-10-13 15:00:58 94 170 94 8000
2015-10-13 15:01:00 95 170 95 8000
2015-10-13 15:01:02 97 171 97 8000
2015-10-13 15:01:04 97 173 97 8000
2015-10-13 15:01:06 97 173 97 8000
2015-10-13 15:01:08 97 174 97 8000
2015-10-13 15:01:10 97 175 97 8000
2015-10-13 15:01:12 97 176 97 8000
2015-10-13 15:01:14 97 181 97 8000
2015-10-13 15:01:16 97 181 97 8000
2015-10-13 15:01:18 97 181 97 8000
... ... ... ... ...
2015-10-15 08:25:58 92 179 92 8000
2015-10-15 08:26:00 92 184 92 8000
2015-10-15 08:26:02 92 187 92 8000
2015-10-15 08:26:04 92 187 92 8000
2015-10-15 08:26:06 92 186 92 8000
2015-10-15 08:26:08 92 183 92 8000
2015-10-15 08:26:10 92 185 92 8000
2015-10-15 08:26:12 92 185 92 8000
2015-10-15 08:26:14 92 185 92 8000
2015-10-15 08:26:16 92 187 92 8000
2015-10-15 08:26:18 92 185 92 8000
2015-10-15 08:26:20 92 183 92 8000
2015-10-15 08:26:22 92 183 92 8000
2015-10-15 08:26:24 91 183 91 8000
2015-10-15 08:26:26 91 183 91 8000
2015-10-15 08:26:28 91 183 91 8000
2015-10-15 08:26:30 91 177 91 8000
2015-10-15 08:26:32 91 177 91 8000
2015-10-15 08:26:34 91 177 91 8000
2015-10-15 08:26:36 91 177 91 8000
2015-10-15 08:26:38 91 178 91 8000
2015-10-15 08:26:40 91 180 91 8000
2015-10-15 08:26:42 91 180 91 8000
2015-10-15 08:26:44 91 180 91 8000
2015-10-15 08:26:46 91 180 91 8000
2015-10-15 08:26:48 91 179 91 8000
2015-10-15 08:26:50 91 181 91 8000
2015-10-15 08:26:52 91 181 91 8000
2015-10-15 08:26:54 91 182 91 8000
2015-10-15 08:26:56 92 184 92 8000

71618 rows × 4 columns


In [21]:
PI = df.PI[1:3]
df.PI[1:5].std()


Out[21]:
nan

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


Dialect: "escaped"

['col1', '0', '10/00/2010', 'Contains special chars: \\" \' \\', ' to be parsed']
['col1', '1', '10/01/2010', 'Contains special chars: \\" \' \\', ' to be parsed']
['col1', '2', '10/02/2010', 'Contains special chars: \\" \' \\', ' to be parsed']

Dialect: "excel"

['col1', '0', '10/00/2010', 'Contains special chars: " \' , to be parsed']
['col1', '1', '10/01/2010', 'Contains special chars: " \' , to be parsed']
['col1', '2', '10/02/2010', 'Contains special chars: " \' , to be parsed']

Dialect: "excel-tab"

['col1', '0', '10/00/2010', 'Contains special chars: " \' \t to be parsed']
['col1', '1', '10/01/2010', 'Contains special chars: " \' \t to be parsed']
['col1', '2', '10/02/2010', 'Contains special chars: " \' \t to be parsed']

Dialect: "singlequote"

['col1', '0', '10/00/2010', 'Contains special chars: " \' , to be parsed']
['col1', '1', '10/01/2010', 'Contains special chars: " \' , to be parsed']
['col1', '2', '10/02/2010', 'Contains special chars: " \' , to be parsed']

In [ ]:


In [ ]: