domo-python-sdk icon indicating copy to clipboard operation
domo-python-sdk copied to clipboard

Allow for different encoding with ds_get function

Open GordonDataGroupGrant opened this issue 1 year ago • 0 comments

There are instances where the data I have isn't encoded as utf-8 but a different encoding like latin1. Currently the ds_get funciton assumes utf-8 formatting when returning a pandas dataframe. It'd be nice to have the ability to specify the encoding format

Here's a proposed updated version adding an optional encoding parameter to: https://github.com/domoinc/domo-python-sdk/blob/master/pydomo/init.py#L179

def ds_get(self, dataset_id, encoding='utf-8'):

    """

        Export data to pandas Dataframe


        >>> df = domo.ds_get('80268aef-e6a1-44f6-a84c-f849d9db05fb')

        >>> print(df.head())


        :Parameters:

        - `dataset_id`:     id of a dataset (str)


        :Returns:

        pandas dataframe

    """

    csv_download = self.datasets.data_export(dataset_id, include_csv_header=True)


    content = StringIO(csv_download)

    df = read_csv(content, encoding=encoding)


    # Convert to dates or datetimes if possible

    for col in df.columns:

        if df[col].dtype == 'object':

            try:

                df[col] = to_datetime(df[col])

            except ValueError:

                pass

            except TypeError:

                pass


    return df

GordonDataGroupGrant avatar Nov 09 '23 20:11 GordonDataGroupGrant