athena connector python 1

athena connector python

from pyathena import connect
from pyathena.util import as_pandas

cursor = connect(aws_access_key_id="YOUR_ACCESS_KEY_ID",
                 aws_secret_access_key="YOUR_SECRET_ACCESS_KEY",
                 s3_staging_dir="s3://YOUR_S3_BUCKET/path/to/",
                 region_name="us-west-2").cursor()
cursor.execute("SELECT * FROM many_rows")
df = as_pandas(cursor)
print(df.describe())

Here is what the above code is Doing:
1. Connect to Athena using your AWS credentials and the S3 bucket where you want to store query results.
2. Execute a query.
3. Convert the results to a Pandas DataFrame.
4. Print a summary of the results.

Similar Posts