# 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

***


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sov.ai/api-reference/utils/converter.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
