In [1]:
import warnings
warnings.filterwarnings('ignore')
In [2]:
from datetime import date, time
import pandas as pd
import pylab as pl
import numpy as np
import seaborn as sns
%matplotlib inline
In [3]:
df = pd.read_excel('/media/rafael/KINGSTON/Daten/ALJA_2014_BY/ALJA_2014.xlsx')
In [4]:
df.head(10)
Out[4]:
In [5]:
df['BASt-Nr.'].unique()
Out[5]:
In [6]:
names = ['T', 'K', 'Datum', 'Zeit', 'FS', 'Typ', 'Fzl', 'Nix', 'Abst', 'GG', 'Ul', 'Anz', 'AT1', 'Last1', 'Abst1',
'AT2', 'Last2', 'Abst2', 'AT3', 'Last3', 'Abst3', 'AT4', 'Last4', 'Abst4', 'AT5', 'Last5', 'Abst5',
'AT6', 'Last6', 'Abst6']
In [7]:
fname ='/media/rafael/KINGSTON/Daten/AMS_2014_BY/9625_1402.txt'
achsen_9625 = pd.read_csv(fname, sep='\t', skiprows=3, names=names)
achsen_9625['zst'] = 9625
achsen_9625['Strasse'] = 'A7'
achsen_9625['Ort'] = 'Bottenweiler'
achsen_9625['Route'] = None
In [8]:
fname ='/media/rafael/KINGSTON/Daten/AMS_2014_BY/9627_1402.txt'
achsen_9627 = pd.read_csv(fname, sep='\t', skiprows=3, names=names)
achsen_9627['zst'] = 9627
achsen_9627['Strasse'] = 'A3'
achsen_9627['Ort'] = u'Schlüsselfeld'
achsen_9627['Route'] = 'kurz'
In [9]:
fname ='/media/rafael/KINGSTON/Daten/AMS_2014_BY/9628_1402.txt'
achsen_9628 = pd.read_csv(fname, sep='\t', skiprows=3, names=names)
achsen_9628['zst'] = 9628
achsen_9628['Strasse'] = 'A3'
achsen_9628['Ort'] = 'Aicha vorm Wald'
achsen_9628['Route'] = None
In [10]:
fname ='/media/rafael/KINGSTON/Daten/AMS_2014_BY/9629_1402.txt'
achsen_9629 = pd.read_csv(fname, sep='\t', skiprows=3, names=names)
achsen_9629['zst'] = 9629
achsen_9629['Strasse'] = 'A93'
achsen_9629['Ort'] = 'Fischbach am Inn'
achsen_9629['Route'] = 'lang'
In [11]:
tag = '21.02.2014'
In [12]:
tag_9625 = achsen_9625[achsen_9625.Datum == tag]
tag_9627 = achsen_9627[achsen_9627.Datum == tag]
tag_9628 = achsen_9628[achsen_9628.Datum == tag]
tag_9629 = achsen_9629[achsen_9629.Datum == tag]
In [13]:
def string2datum(datum):
tag, monat, jahr = datum.split('.')
return date(year=int(jahr), month=int(monat), day=int(tag))
def string2zeit(zeit):
h, m, s= zeit.split(':')
return time(hour=int(h), minute=int(m))
In [14]:
tag_9625['Datum'] = tag_9625.Datum.apply(lambda x: string2datum(x))
tag_9625['Zeit'] = tag_9625.Zeit.apply(lambda x: string2zeit(x))
tag_9627['Datum'] = tag_9627.Datum.apply(lambda x: string2datum(x))
tag_9627['Zeit'] = tag_9627.Zeit.apply(lambda x: string2zeit(x))
tag_9628['Datum'] = tag_9628.Datum.apply(lambda x: string2datum(x))
tag_9628['Zeit'] = tag_9628.Zeit.apply(lambda x: string2zeit(x))
tag_9629['Datum'] = tag_9629.Datum.apply(lambda x: string2datum(x))
tag_9629['Zeit'] = tag_9629.Zeit.apply(lambda x: string2zeit(x))
In [15]:
keep = ['T', 'K', 'Datum', 'Zeit', 'FS', 'Typ', 'Fzl', 'Abst', 'GG', 'Ul', 'Anz', 'zst', 'Strasse', 'Ort', 'Route']
In [16]:
tag_9625 = tag_9625[keep]
tag_9627 = tag_9627[keep]
tag_9628 = tag_9628[keep]
tag_9629 = tag_9629[keep]
In [17]:
tag_9625['Stunde'] = tag_9625.Zeit.apply(lambda x: x.hour)
tag_9627['Stunde'] = tag_9627.Zeit.apply(lambda x: x.hour)
tag_9628['Stunde'] = tag_9628.Zeit.apply(lambda x: x.hour)
tag_9629['Stunde'] = tag_9629.Zeit.apply(lambda x: x.hour)
In [18]:
tag_9625 = tag_9625.set_index('Zeit')
tag_9627 = tag_9627.set_index('Zeit')
tag_9628 = tag_9628.set_index('Zeit')
tag_9629 = tag_9629.set_index('Zeit')
In [19]:
frame = pd.concat([tag_9625, tag_9627, tag_9628, tag_9629])
In [20]:
def fs_to_richtung(fs):
if fs <= 6:
return 1
return 2
In [21]:
frame['Richtung'] = frame.FS.apply(lambda x: fs_to_richtung(x))
In [22]:
kurz = frame[frame.Route == 'kurz']
lang = frame[frame.Route == 'lang']
In [23]:
for richtung in frame.Richtung.unique():
fig, ax = pl.subplots(1, figsize=(16, 9))
kurz_per_hour = kurz[kurz.Richtung == richtung].groupby('Stunde').sum()
lang_per_hour = lang[lang.Richtung == richtung].groupby('Stunde').sum()
x = np.arange(len(kurz_per_hour))
ax.plot(x, kurz_per_hour.GG, label='kurz')
ax.plot(x, lang_per_hour.GG, label='lang')
ax.set_xlim([0, 23])
ax.set_title('Gesamtgewicht / h - Richtung {}'.format(richtung), fontsize=20)
ax.legend(fontsize=20);
ax.axvspan(.1, 6, color='r', alpha=0.2, lw=0)
ax.axvspan(19, 24, color='r', alpha=0.2, lw=0);