5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PythonからS3にあるcsvをデータフレームにして読み込む

Last updated at Posted at 2018-05-31

#aws 上のpythonファイルから読み込む

import pandas as pd
import boto3
df = pd.read_csv('s3n://バケット名/ファイル名.csv')

ローカルのpythonファイルから読み込む

import pandas as pd
import boto3
from io import StringIO

s3 = boto3.client('s3')
obj = s3.get_object(Bucket='バケット名', Key='ファイル名.csv')
body = obj['Body']
csv_string = body.read().decode('utf-8')
df = pd.read_csv(StringIO(csv_string))

上の方が楽だけど、ローカルからはなぜかできなかった。

5
4
0

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
5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?