Converter

API reference for sovai.utils.converter

Module: sovai.utils.converter

Functions

process_dataframe()

def process_dataframe(df)

Processes the DataFrame to convert 'Date' column to datetime and sets appropriate indices.

It handles different naming conventions for 'Date' and 'ticker(s)' columns. If 'Date' column exists, it is converted to datetime and set as an index. If 'ticker' or 'tickers' column also exists, a MultiIndex of ('ticker(s)', 'Date') is created.

Parameters

Parameter
Type
Description

df

The DataFrame to process.

Returns

: The processed DataFrame with the 'Date' as the datetime index or a MultiIndex with 'ticker(s)' and 'Date'.


convert_data2df()

def convert_data2df(response: Union[dict, list]) -> Union[pd.DataFrame, Any]

This function gets a nested dict or list from API, then processes it:

  • If "response" is a DataFrame, it returns it directly.

  • If "response" is a dict with a depth of 1 and evenly contains lists, it converts it to a DataFrame.

  • If "response" is a list and not charts data, it converts it to a DataFrame. If "response" is a dict containing 'data' and 'columns_order', it will reorder the DataFrame columns accordingly.

Parameters

Parameter
Type
Description

response

Union[dict, list]

raw data from api

Returns

: DataFrame or the original response if it cannot be converted


Last updated