Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

311
Views
Lea un archivo csv de aws s3 usando boto y pandas

Ya he leído las respuestas disponibles aquí y aquí y estas no ayudan.

Estoy tratando de leer un objeto csv del depósito S3 y he podido leer correctamente los datos usando el siguiente código.

 srcFileName="gossips.csv" def on_session_started(): print("Starting new session.") conn = S3Connection() my_bucket = conn.get_bucket("randomdatagossip", validate=False) print("Bucket Identified") print(my_bucket) key = Key(my_bucket,srcFileName) key.open() print(key.read()) conn.close() on_session_started()

Sin embargo, si trato de leer el mismo objeto usando pandas como marco de datos, aparece un error. El más común es S3ResponseError: 403 Forbidden

 def on_session_started2(): print("Starting Second new session.") conn = S3Connection() my_bucket = conn.get_bucket("randomdatagossip", validate=False) # url = "https://s3.amazonaws.com/randomdatagossip/gossips.csv" # urllib2.urlopen(url) for line in smart_open.smart_open('s3://my_bucket/gossips.csv'): print line # data = pd.read_csv(url) # print(data) on_session_started2()

¿Qué estoy haciendo mal? Estoy en Python 2.7 y no puedo usar Python 3.

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Esto es lo que he hecho para leer con éxito el df de un csv en S3.

 import pandas as pd import boto3 bucket = "yourbucket" file_name = "your_file.csv" s3 = boto3.client('s3') # 's3' is a key word. create connection to S3 using default config and all buckets within S3 obj = s3.get_object(Bucket= bucket, Key= file_name) # get object and file (key) from bucket initial_df = pd.read_csv(obj['Body']) # 'Body' is a key word
about 4 years ago · Santiago Trujillo Report

0

Esto funcionó para mí.

 import pandas as pd import boto3 import io s3_file_key = 'data/test.csv' bucket = 'data-bucket' s3 = boto3.client('s3') obj = s3.get_object(Bucket=bucket, Key=s3_file_key) initial_df = pd.read_csv(io.BytesIO(obj['Body'].read()))
about 4 years ago · Santiago Trujillo Report

0

Tal vez puedas intentar usar pandas read_sql y pyathena:

 from pyathena import connect import pandas as pd conn = connect(s3_staging_dir='s3://bucket/folder',region_name='region') df = pd.read_sql('select * from database.table', conn)
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!