In [ ]:
ls

Plan:

  1. load the data into pandas dataform (done)
  2. reformat it as the way we want

In [7]:
import pandas as pd
import numpy as np

In [8]:
#from datetime import datetime

#headers = ['col1', 'col2', 'col3', 'col4'] 
#dtypes = [datetime, datetime, str, float] 

# pd.read_csv(file, sep='\t', header=None, names=headers, dtype=dtypes)

In [9]:
df = pd.read_csv('./data1.csv', parse_dates=True)

In [10]:
df.head(3)


Out[10]:
tagname time value1 value2
0 FL02.X05_Z4105.f_CV 12/12/2016 09:00:30 5.90 0.16
1 FL02.X05_Z4105.f_CV 12/12/2016 09:01:30 5.10 0.45
2 FL02.X05_Z4105.f_CV 12/12/2016 09:02:30 5.11 0.55

In [11]:
df


Out[11]:
tagname time value1 value2
0 FL02.X05_Z4105.f_CV 12/12/2016 09:00:30 5.90 0.16
1 FL02.X05_Z4105.f_CV 12/12/2016 09:01:30 5.10 0.45
2 FL02.X05_Z4105.f_CV 12/12/2016 09:02:30 5.11 0.55
3 FL02.X05_Z4104.f_CV 12/12/2016 09:00:30 6.87 0.44
4 FL02.X05_Z4104.f_CV 12/12/2016 09:01:30 6.88 0.34
5 FL02.X05_Z4104.f_CV 12/12/2016 09:02:30 6.89 0.92
6 FL02.X05_Z4103.f_CV 12/12/2016 09:00:30 4.67 0.96
7 FL02.X05_Z4103.f_CV 12/12/2016 09:01:30 4.77 0.90
8 FL02.X05_Z4103.f_CV 12/12/2016 09:02:30 4.78 0.27

In [12]:
df.columns


Out[12]:
Index([u'tagname', u'time', u'value1', u'value2'], dtype='object')

In [13]:
df['time'].dtype


Out[13]:
dtype('O')

Split the data in 3 group


In [14]:
df1 = df[ df['tagname'] == 'FL02.X05_Z4105.f_CV']

In [15]:
df1


Out[15]:
tagname time value1 value2
0 FL02.X05_Z4105.f_CV 12/12/2016 09:00:30 5.90 0.16
1 FL02.X05_Z4105.f_CV 12/12/2016 09:01:30 5.10 0.45
2 FL02.X05_Z4105.f_CV 12/12/2016 09:02:30 5.11 0.55

In [16]:
df_grouped = df.groupby('tagname')

In [32]:
# df_grouped.agg()

In [18]:
tag_names = df['tagname'].unique()

In [19]:
tag_names


Out[19]:
array(['FL02.X05_Z4105.f_CV', 'FL02.X05_Z4104.f_CV', 'FL02.X05_Z4103.f_CV'], dtype=object)

In [66]:
tag_names = df['tagname'].unique() # gets the unique tag names
data_dic = {} # create an empty dictionary (map)

for name in tag_names: # use the unique name to assemble a dictionary, with name as key, value as selected data
    # print(name)
    data_dic[name[12: 14]] = df[ df['tagname'] == name]
    
# data_dic

In [42]:
animals = ['chiken', 'tiger', 'snake', 'snail']

for animal in animals :
    
    if len(animal) <=5 :
        print(animal + ' is good')
    else :
        print(animal + ' sucks')


chiken sucks
tiger is good
snake is good
snail is good

In [ ]:


In [21]:
dummy_dic = {
    'FL02.X05_Z4105.f_CV': 100,
    'FL02.X05_Z4104.f_CV': 200,
    'FL02.X05_Z4103.f_CV': df
}

In [30]:
data_dic['FL02.X05_Z4103.f_CV']


Out[30]:
tagname time value1 value2
6 FL02.X05_Z4103.f_CV 12/12/2016 09:00:30 4.67 0.96
7 FL02.X05_Z4103.f_CV 12/12/2016 09:01:30 4.77 0.90
8 FL02.X05_Z4103.f_CV 12/12/2016 09:02:30 4.78 0.27

In [44]:
dummy_dic['fuyang'] = 'Awesome guy'

In [47]:
len(dummy_dic)


Out[47]:
4

In [51]:
name


Out[51]:
'FL02.X05_Z4103.f_CV'

In [54]:
df['tagname'] == name


Out[54]:
0    False
1    False
2    False
3    False
4    False
5    False
6     True
7     True
8     True
Name: tagname, dtype: bool

In [58]:
df[ df['tagname'] == name]


Out[58]:
tagname time value1 value2
6 FL02.X05_Z4103.f_CV 12/12/2016 09:00:30 4.67 0.96
7 FL02.X05_Z4103.f_CV 12/12/2016 09:01:30 4.77 0.90
8 FL02.X05_Z4103.f_CV 12/12/2016 09:02:30 4.78 0.27

In [68]:
data_dic['03']


Out[68]:
tagname time value1 value2
6 FL02.X05_Z4103.f_CV 12/12/2016 09:00:30 4.67 0.96
7 FL02.X05_Z4103.f_CV 12/12/2016 09:01:30 4.77 0.90
8 FL02.X05_Z4103.f_CV 12/12/2016 09:02:30 4.78 0.27

Do some simple plot


In [1]:
%matplotlib inline 
import matplotlib.pyplot as plt


Vendor:  Continuum Analytics, Inc.
Package: mkl
Message: trial mode expires in 30 days

In [5]:
plt.plot([1,2,3,4], [3,4,5,6])
plt.plot([1,2,3,4], [2,1,3,4])
plt.ylabel('some numbers')
plt.show()



In [28]:
df103 = data_dic['FL02.X05_Z4103.f_CV']
plt.plot(df103['time'], df103['value1'])
plt.show()


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-28-2e8016976aaa> in <module>()
      1 
      2 df103 = data_dic['FL02.X05_Z4103.f_CV']
----> 3 plt.plot(df103['time'], df103['value1'])
      4 plt.show()

/Users/fuyangliu/anaconda/lib/python2.7/site-packages/matplotlib/pyplot.pyc in plot(*args, **kwargs)
   3152         ax.hold(hold)
   3153     try:
-> 3154         ret = ax.plot(*args, **kwargs)
   3155     finally:
   3156         ax.hold(washold)

/Users/fuyangliu/anaconda/lib/python2.7/site-packages/matplotlib/__init__.pyc in inner(ax, *args, **kwargs)
   1809                     warnings.warn(msg % (label_namer, func.__name__),
   1810                                   RuntimeWarning, stacklevel=2)
-> 1811             return func(ax, *args, **kwargs)
   1812         pre_doc = inner.__doc__
   1813         if pre_doc is None:

/Users/fuyangliu/anaconda/lib/python2.7/site-packages/matplotlib/axes/_axes.pyc in plot(self, *args, **kwargs)
   1426 
   1427         for line in self._get_lines(*args, **kwargs):
-> 1428             self.add_line(line)
   1429             lines.append(line)
   1430 

/Users/fuyangliu/anaconda/lib/python2.7/site-packages/matplotlib/axes/_base.pyc in add_line(self, line)
   1697             line.set_clip_path(self.patch)
   1698 
-> 1699         self._update_line_limits(line)
   1700         if not line.get_label():
   1701             line.set_label('_line%d' % len(self.lines))

/Users/fuyangliu/anaconda/lib/python2.7/site-packages/matplotlib/axes/_base.pyc in _update_line_limits(self, line)
   1708         Figures out the data limit of the given line, updating self.dataLim.
   1709         """
-> 1710         path = line.get_path()
   1711         if path.vertices.size == 0:
   1712             return

/Users/fuyangliu/anaconda/lib/python2.7/site-packages/matplotlib/lines.pyc in get_path(self)
    924         """
    925         if self._invalidy or self._invalidx:
--> 926             self.recache()
    927         return self._path
    928 

/Users/fuyangliu/anaconda/lib/python2.7/site-packages/matplotlib/lines.pyc in recache(self, always)
    609                 x = ma.asarray(xconv, np.float_).filled(np.nan)
    610             else:
--> 611                 x = np.asarray(xconv, np.float_)
    612             x = x.ravel()
    613         else:

/Users/fuyangliu/anaconda/lib/python2.7/site-packages/numpy/core/numeric.pyc in asarray(a, dtype, order)
    472 
    473     """
--> 474     return array(a, dtype, copy=False, order=order)
    475 
    476 def asanyarray(a, dtype=None, order=None):

ValueError: invalid literal for float(): 12/12/2016 09:02:30

In [ ]:
df.dr

In [ ]: