Input/Output data#
Shapelets supports a variety of data sources to create Dataframe-like structures to process data.
To load or save data, you need to create a sandbox on Shapelets first, you can do like:
>>> import shapelets as sh
>>> session = sh.sandbox()
Read Data#
Read from csv files#
You can read csv files using the from_csv() function. A basic example is:
>>> df = session.from_csv(path)
This reader function has automatic delimiter/separator detection, so you do not need to specify the delimiter!
This function has more params, like date_format to specify the date format on date columns, and even more. You can check it out on the API Reference in from_csv()
Read from parquet files#
You can use the from_parquet() function to load parquet files. A basic example here:
>>> df = session.from_parquet(path)
This function has more params, which you can find in the API Reference in from_parquet()
.
Read from Pandas DataFrame#
In the case that you have a Pandas DataFrame which you woud like to quickly load in Shapelets, you can do it so using from_pandas() function:
>>> pandas_df = pd.DataFrame(data)
>>> df = session.from_pandas(pandas_df)
Export/Save Data#
Save to a csv file#
To save the content of a Shapelets Dataframe into a csv file, you can use the to_csv() function.
>>> df.to_csv(filename, delimiter=",")
This function has more params, which you can find in the API Reference in to_csv()
.
Save to a parquet file#
If you want save the contents of a Shapelets Dataframe into a parquet file, you can use the to_parquet() function.
>>> df.to_parquet(filename, delimiter=",")
This function has more params, which you can find in the API Reference in to_parquet()
.
Convert into Pandas DataFrame#
You can load data into Shapelets, process it and convert the results directly to a Pandas Dataframe object to use it with Pandas functions or any other Python library. Here is an example:
>>> df.to_pandas()