How to Create Dataframe from AWS Athena using Boto3 get_query_results method

前端 未结 5 2176
广开言路
广开言路 2021-02-13 05:37

I\'m using AWS Athena to query raw data from S3. Since Athena writes the query output into S3 output bucket I used to do:

df = pd.read_csv(OutputLocation)
         


        
5条回答
  •  感情败类
    2021-02-13 06:31

    Try this approach to convert response['records'] into dataframe using columnMetadata:

    def results_to_df(response):
        columns = [
            col['label']
            for col in response['columnMetadata']
        ]
    
        listed_results = [[list(col.values())[0] if list(col.values())[0] else '' for col in 
        record] for record in response['records']]
        df = pd.DataFrame(listed_results, columns=columns)
        return df
    

提交回复
热议问题