Input/Output of cycling dataΒΆ

This example illustrates the usage of skcycling.io.bikeread to read cycling data. We also show how to export the data using pandas.

# Authors: Guillaume Lemaitre <g.lemaitre58@gmail.com>
# License: BSD 3 clause

print(__doc__)

scikit-cycling has couple of fit files stored which can be used as toy data.

from skcycling.datasets import load_fit

filename_fit = load_fit()[0]  # catch the first toy file
print('The fit file which will be used is stored at: \n {}'
      .format(filename_fit))

Out:

The fit file which will be used is stored at:
 /home/docs/checkouts/readthedocs.org/user_builds/scikit-cycling/envs/stable/local/lib/python2.7/site-packages/skcycling/datasets/data/2014-05-07-14-26-22.fit

The function skcycling.io.bikeread allows to read the file without any extra information regarding the format.

from skcycling.io import bikeread

ride = bikeread(filename_fit)
print('The ride is the following:\n {}'.format(ride.head()))

Out:

The ride is the following:
                      elevation  cadence  distance  heart-rate  power  speed
2014-05-07 12:26:22       64.8     45.0      3.05         NaN  256.0  3.036
2014-05-07 12:26:23       64.8     42.0      6.09         NaN  185.0  3.053
2014-05-07 12:26:24       64.8     44.0      9.09         NaN  343.0  3.004
2014-05-07 12:26:25       64.8     45.0     11.94         NaN  344.0  2.846
2014-05-07 12:26:26       65.8     48.0     15.03         NaN  389.0  3.088

skcycling.io.bikeread returns a pandas DataFrame. Thus, this is possible to export it in different format. We will use CSV format in this case.

filename_export = 'ride_exported.csv'
ride.to_csv(filename_export)

Then, it is always possible to read the file exported using pandas

import pandas as pd

ride_exported = pd.read_csv(filename_export, index_col=0, parse_dates=True)
print('The ride exported and loaded is the following:\n {}'
      .format(ride_exported.head()))

Out:

The ride exported and loaded is the following:
                      elevation  cadence  distance  heart-rate  power  speed
2014-05-07 12:26:22       64.8     45.0      3.05         NaN  256.0  3.036
2014-05-07 12:26:23       64.8     42.0      6.09         NaN  185.0  3.053
2014-05-07 12:26:24       64.8     44.0      9.09         NaN  343.0  3.004
2014-05-07 12:26:25       64.8     45.0     11.94         NaN  344.0  2.846
2014-05-07 12:26:26       65.8     48.0     15.03         NaN  389.0  3.088

Some cleaning

import os
os.remove(filename_export)  # remove the file

Total running time of the script: ( 0 minutes 0.949 seconds)

Gallery generated by Sphinx-Gallery