hyper-api-samples
hyper-api-samples copied to clipboard
Request: Column Names Added to Results Object
Request: I'd like to request the connection.execute_query function to automatically output the column names to the Results object created. These should be the list of column names from submitted query (all columns if SELECT * used)
Purpose: Automatically creates column names for Results object (dataframe), which makes it easier for reference later on if needed.
Alternative (in case of technical limitation):
- create empty list
- iterate over list of columns for desired table using <table_obj_name>.columns 2.a.) extract column name using name method from object 2.b.) convert returned column name to string (using __str__() ), because it's originally returned as tabledefinition object 2.c.) append to list
- use connection.execute_query function for desired query that creates Results object, and then pass completed list of columns from 2.c. above as argument for columns when dataframe is created
Screenshot attached with example

Hi @successfulmike,
The results object contains a schema which holds the columns.
You can access it via
result.schema.columns
Please let me know if this solves your issue.
Cheers Jonas
@successfulmike for integration with pandas, you might want to look into pantab.
https://pantab.readthedocs.io/en/latest/examples.html contains a couple of usage examples
@jonas-eckhardt , though that suggestion is valid, it still returns a TableDefinition object like shown in the example in my screenshot so you'd still need to perform transformation to extract column name and convert to string type.
The good thing about your approach though is that we don't need to worry about figuring out what the returned list of columns from the queries would be, so I guess that's certainly a plus. Thanks for sharing.
@successfulmike does pantab (as suggested by Adrian) solve the issue?
solving based on inactivity; in case the issue wasn't resolved, yet, feel free to reopen