LoginSignup
0

More than 3 years have passed since last update.

2行でs3にあるファイルを読み込みpandasに食わせる

Last updated at Posted at 2019-09-11

最近、データを集計してs3にバックアップして、そのデータをロードして、別のサービスに取り込むことが増えてきました。

で、モジュールを調べたらsmart_openに出くわしました。

超便利なので、紹介します。

import pandas as pd

with smart_open("s3://some_bucket_name/ai_score/2020/09/09.csv.bz2", "r") as f
   df = pd.read_csv(f)  # f == encodings.utf_8.StreamReader

SmartOpen: https://pypi.org/project/smart-open/

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0