python-pandas and databases like mysql

后端 未结 13 2073
有刺的猬
有刺的猬 2020-12-02 03:51

The documentation for Pandas has numerous examples of best practices for working with data stored in various formats.

However, I am unable to find any good examples

相关标签:
13条回答
  • 2020-12-02 04:30

    This helped for me for connecting to AWS MYSQL(RDS) from python 3.x based lambda function and loading into a pandas DataFrame

    import json
    import boto3
    import pymysql
    import pandas as pd
    user = 'username'
    password = 'XXXXXXX'
    client = boto3.client('rds')
    def lambda_handler(event, context):
        conn = pymysql.connect(host='xxx.xxxxus-west-2.rds.amazonaws.com', port=3306, user=user, passwd=password, db='database name', connect_timeout=5)
        df= pd.read_sql('select * from TableName limit 10',con=conn)
        print(df)
        # TODO implement
        #return {
        #    'statusCode': 200,
        #    'df': df
        #}
    
    0 讨论(0)
提交回复
热议问题