I/O
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
1) 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_forma to specify the date format on date columns, and even more.
You can check it out on the API Reference in from_csv()
2) Read from parquet files
You can use from_parquet()
to load parquet files.
A basic example here:
df = session.from_parquet(path)
This function has more parameters, which you can find in the API Reference: from_parquet()
3) Read from Pandas DataFrames
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
1) 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()
2) 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()
3) Convert into a 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()