Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for different encoding with ds_get function #97

Open
GordonDataGroupGrant opened this issue Nov 9, 2023 · 0 comments
Open

Allow for different encoding with ds_get function #97

GordonDataGroupGrant opened this issue Nov 9, 2023 · 0 comments

Comments

@GordonDataGroupGrant
Copy link

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant