In [1]:
%reset


Once deleted, variables cannot be recovered. Proceed (y/[n])? y

In [3]:
from pandas import Series, DataFrame
import pandas as pd
import numpy as np
import csv
import math
import matplotlib.pyplot as plt
from scipy.signal import hilbert, chirp
import scipy

In [4]:
c_dist = ['Timestamp','vIDa', 'vIDb', 'dist_ab', 'v_a_Type', 'v_a_Vel', 'v_a_Line', 'v_a_Pred', 'v_a_Foll']

data_dist = pd.read_table('D:\\zzzLola\\PhD\\DataSet\\US101\\test\\dist_1000ts.txt', sep='\t', header=None, names=c_dist)

In [5]:
c_vehic = ['vIDa', 'count','mean_vel']

data_vehic = pd.read_table('D:\\zzzLola\\PhD\\DataSet\\US101\\test\\vehi_1000ts.txt', sep='\t', header=None, names=c_vehic)

In [6]:
dataset = pd.merge(data_dist,data_vehic, on = 'vIDa')

In [7]:
dataset['dist_ab'] = dataset.dist_ab * 0.3048
dataset['v_a_Vel'] = dataset.v_a_Vel * 0.3048
dataset['mean_vel'] = dataset.mean_vel * 0.3048
dataset[:10]


Out[7]:
Timestamp vIDa vIDb dist_ab v_a_Type v_a_Vel v_a_Line v_a_Pred v_a_Foll count mean_vel
0 1.118847e+12 1073 1077 26.760834 2 18.263616 2 0 1083 22 18.18894
1 1.118847e+12 1073 1080 9.739521 2 18.263616 2 0 1083 22 18.18894
2 1.118847e+12 1073 1081 19.198605 2 18.263616 2 0 1083 22 18.18894
3 1.118847e+12 1073 1082 20.679750 2 18.263616 2 0 1083 22 18.18894
4 1.118847e+12 1073 1083 56.396881 2 18.263616 2 0 1083 22 18.18894
5 1.118847e+12 1073 1084 40.510313 2 18.263616 2 0 1083 22 18.18894
6 1.118847e+12 1073 1086 56.592865 2 18.263616 2 0 1083 22 18.18894
7 1.118847e+12 1073 1087 19.093697 2 18.263616 2 0 1083 22 18.18894
8 1.118847e+12 1073 1088 83.171880 2 18.263616 2 0 1083 22 18.18894
9 1.118847e+12 1073 1089 15.309671 2 18.263616 2 0 1083 22 18.18894

In [8]:
dataset['delt_vel'] = dataset.v_a_Vel - dataset.mean_vel

#dataset['delt_vel'] = delta_vel

In [9]:
dataset[:10]


Out[9]:
Timestamp vIDa vIDb dist_ab v_a_Type v_a_Vel v_a_Line v_a_Pred v_a_Foll count mean_vel delt_vel
0 1.118847e+12 1073 1077 26.760834 2 18.263616 2 0 1083 22 18.18894 0.074676
1 1.118847e+12 1073 1080 9.739521 2 18.263616 2 0 1083 22 18.18894 0.074676
2 1.118847e+12 1073 1081 19.198605 2 18.263616 2 0 1083 22 18.18894 0.074676
3 1.118847e+12 1073 1082 20.679750 2 18.263616 2 0 1083 22 18.18894 0.074676
4 1.118847e+12 1073 1083 56.396881 2 18.263616 2 0 1083 22 18.18894 0.074676
5 1.118847e+12 1073 1084 40.510313 2 18.263616 2 0 1083 22 18.18894 0.074676
6 1.118847e+12 1073 1086 56.592865 2 18.263616 2 0 1083 22 18.18894 0.074676
7 1.118847e+12 1073 1087 19.093697 2 18.263616 2 0 1083 22 18.18894 0.074676
8 1.118847e+12 1073 1088 83.171880 2 18.263616 2 0 1083 22 18.18894 0.074676
9 1.118847e+12 1073 1089 15.309671 2 18.263616 2 0 1083 22 18.18894 0.074676

In [10]:
np.savetxt('D:\\zzzLola\\PhD\\DataSet\\US101\\test\\dataset.txt',dataset, fmt='%.10e', delimiter='\t', newline='\n')

In [10]:
type(dataset)


Out[10]:
pandas.core.frame.DataFrame

In [11]:
del t


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-11-14ac1cb05b5a> in <module>()
----> 1 del t

NameError: name 't' is not defined

In [ ]:
dataset.groupby(['Timestamp', 'vIDa']).mean()

In [ ]:
v1280 = dataset.loc[dataset['vIDa'] == 1280]

In [ ]:
v1280.groupby('v_a_Line').count()

In [ ]:
for key, grp in dataset.groupby(['Timestamp']):
    plt.plot(grp['vIDa'], label=key)
    grp['mean_vel'] = pd.rolling_mean(grp['vIDa'], window=5)    
    plt.plot(grp['mean_vel'], label='rolling ({k})'.format(k=key))
plt.legend(loc='best')    
plt.show()

In [40]:



---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-40-45b2189a6a0b> in <module>()
----> 1 dataset.groupby(['vIDa']).apply(toeach_category)

C:\Anaconda2\lib\site-packages\pandas\core\groupby.pyc in apply(self, func, *args, **kwargs)
    713         # ignore SettingWithCopy here in case the user mutates
    714         with option_context('mode.chained_assignment',None):
--> 715             return self._python_apply_general(f)
    716 
    717     def _python_apply_general(self, f):

C:\Anaconda2\lib\site-packages\pandas\core\groupby.pyc in _python_apply_general(self, f)
    717     def _python_apply_general(self, f):
    718         keys, values, mutated = self.grouper.apply(f, self._selected_obj,
--> 719                                                    self.axis)
    720 
    721         return self._wrap_applied_output(keys, values,

C:\Anaconda2\lib\site-packages\pandas\core\groupby.pyc in apply(self, f, data, axis)
   1404             # group might be modified
   1405             group_axes = _get_axes(group)
-> 1406             res = f(group)
   1407             if not _is_indexed_like(res, group_axes):
   1408                 mutated = True

C:\Anaconda2\lib\site-packages\pandas\core\groupby.pyc in f(g)
    709         @wraps(func)
    710         def f(g):
--> 711             return func(g, *args, **kwargs)
    712 
    713         # ignore SettingWithCopy here in case the user mutates

<ipython-input-37-3096143b616e> in toeach_category(subf)
      1 def toeach_category(subf):
----> 2     result = subf[['Timestamp']].applymap(percentage)

NameError: global name 'percentage' is not defined

In [ ]: