Write pandas dataframe as compressed CSV directly to Amazon s3 bucket?

后端 未结 3 434
醉酒成梦
醉酒成梦 2021-01-02 23:09

I currently have a script that reads the existing version of a csv saved to s3, combines that with the new rows in the pandas dataframe, and then writes that directly back t

3条回答
  •  春和景丽
    2021-01-02 23:50

    There is a more elegant solution using smart-open (https://pypi.org/project/smart-open/)

    import pandas as pd
    from smart_open import open
    
    df.to_csv(open('s3://bucket/prefix/filename.csv.gz','w'),index = False)
    

提交回复
热议问题