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

1.5K
Views
Escribir un archivo pickle en un depósito s3 en AWS

Estoy tratando de escribir un marco de datos de pandas como un archivo pickle en un depósito s3 en AWS. Sé que puedo escribir dataframe new_df como csv en un depósito s3 de la siguiente manera:

 bucket='mybucket' key='path' csv_buffer = StringIO() s3_resource = boto3.resource('s3') new_df.to_csv(csv_buffer, index=False) s3_resource.Object(bucket,path).put(Body=csv_buffer.getvalue())

Intenté usar el mismo código que el anterior con to_pickle() pero sin éxito.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Además de su respuesta, no necesita convertir a csv. El método pickle.dumps devuelve un byte obj. ver aquí: https://docs.python.org/3/library/pickle.html

 import boto3 import pickle bucket='your_bucket_name' key='your_pickle_filename.pkl' pickle_byte_obj = pickle.dumps([var1, var2, ..., varn]) s3_resource = boto3.resource('s3') s3_resource.Object(bucket,key).put(Body=pickle_byte_obj)
over 4 years ago · Santiago Trujillo Report

0

Encontré la solución, necesito llamar a BytesIO en el búfer para archivos pickle en lugar de StringIO (que son para archivos CSV).

 import io import boto3 pickle_buffer = io.BytesIO() s3_resource = boto3.resource('s3') new_df.to_pickle(pickle_buffer) s3_resource.Object(bucket, key).put(Body=pickle_buffer.getvalue())
over 4 years ago · Santiago Trujillo Report

0

esto funcionó para mí con pandas 0.23.4 y boto3 1.7.80:

 bucket='your_bucket_name' key='your_pickle_filename.pkl' new_df.to_pickle(key) s3_resource.Object(bucket, key).put(Body=open(key, 'rb'))
over 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!