Input/Output of cycling dataΒΆ

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

# Authors: Guillaume Lemaitre <g.lemaitre58@gmail.com>
# License: MIT

print(__doc__)

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

from sksports.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-sports/envs/latest/local/lib/python2.7/site-packages/sksports/datasets/data/2014-05-07-14-26-22.fit

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

from sksports.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  ...    power  speed
2014-05-07 12:26:22       64.8     45.0  ...    256.0  3.036
2014-05-07 12:26:23       64.8     42.0  ...    185.0  3.053
2014-05-07 12:26:24       64.8     44.0  ...    343.0  3.004
2014-05-07 12:26:25       64.8     45.0  ...    344.0  2.846
2014-05-07 12:26:26       65.8     48.0  ...    389.0  3.088

[5 rows x 6 columns]

sksports.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  ...    power  speed
2014-05-07 12:26:22       64.8     45.0  ...    256.0  3.036
2014-05-07 12:26:23       64.8     42.0  ...    185.0  3.053
2014-05-07 12:26:24       64.8     44.0  ...    343.0  3.004
2014-05-07 12:26:25       64.8     45.0  ...    344.0  2.846
2014-05-07 12:26:26       65.8     48.0  ...    389.0  3.088

[5 rows x 6 columns]

Some cleaning

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

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

Gallery generated by Sphinx-Gallery