Skip to content

Allow for different encoding with ds_get function #97

@GordonDataGroupGrant

Description

@GordonDataGroupGrant

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions