> For the complete documentation index, see [llms.txt](https://docs.sov.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sov.ai/api-reference/utils/converter.md).

# Converter

**Module:** `sovai.utils.converter`

## Functions

### `process_dataframe()`

```python
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()`

```python
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

***
