<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Zürich bike counter data
Contents
Step1:  Pre-process the dataset
Read input files
Step2:  Remove non relevant columns
Step3:  Remove NaNs
Step4:  Translate column names to English
Step5:  Convert datetime strings to datetime objects
Step6:  Explore the data
Question
Step7:  Let's plot the data for each station, binning on a weekly basis
<ASSISTANT_TASK:>
Python Code:
import os
from glob import glob
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline
Explanation: Zürich bike counter data
Contents:
- Read input files
- Remove non relevant columns
- Remove NaNs
- Translate column names to English
- Convert datetime strings to datetime objects
- Store data in feather format
- Explore the dataset, make visualizations
End of explanation
input_folder = '../data/zhbikes'
input_files = glob('{}/*.csv'.format(input_folder))
dataframes = [pd.read_csv(file)[['fk_zaehler','datum','velo_in','velo_out','fuss_in','fuss_out','objectid']] for file in input_files]
df = pd.concat(dataframes)
df.shape
df.head()
df.dtypes
Explanation: Pre-process the dataset
Read input files
End of explanation
df.drop(['fuss_in','fuss_out'], axis=1, inplace=True)
Explanation: Remove non relevant columns
End of explanation
df.dropna(inplace=True)
Explanation: Remove NaNs
End of explanation
df.columns = ['counting_station','datetime','velo_in', 'velo_out', 'objectid']
Explanation: Translate column names to English
End of explanation
df['datetime'] = df['datetime'].apply(pd.Timestamp)
df.head()
Explanation: Convert datetime strings to datetime objects
End of explanation
stations = df['counting_station'].unique()
stations.shape
Explanation: Explore the data
Question: How many stations do we find in the data?
End of explanation
def sum_by_week(station):
    df_station = df[df['counting_station'] == station]
    aggregated = df_station.set_index('datetime').resample('1W').agg({'velo_in' : 'sum', 'velo_out': 'sum'}).reset_index()
    aggregated['velo_all'] = aggregated['velo_out'] + aggregated['velo_in']
    aggregated['velo_out'] = -aggregated['velo_out']
    aggregated['counting_station'] = station
    return aggregated
dataframes_weekly = [sum_by_week(station) for station in stations]
df_weekly = pd.concat(dataframes_weekly).reset_index(drop=True)
sns.set(font_scale=2)
grid = sns.FacetGrid(df_weekly, col="counting_station", hue="counting_station", palette="tab20c",
                     col_wrap=4, height=3, aspect=3)
grid.map(plt.plot, "datetime", "velo_in")
grid.map(plt.plot, "datetime", "velo_out")
grid.map(plt.axhline, y=0, ls=":", c=".5")
grid.set_xticklabels(rotation=30)
sns.set(rc={'figure.figsize':(15, 10)})
sns.lineplot(x="datetime", y="velo_all", hue="counting_station", data=df_weekly)
Explanation: Let's plot the data for each station, binning on a weekly basis
End of explanation
<END_TASK>