0
0

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 3 years have passed since last update.

pandas 辞書にバリュー(値)を追加する

Posted at

やりたいこと

決まったキーを持つデータをfor文で回して1つのデータにしたい。
APIで毎分データを取得する。それを1つのデータにしたかった。

方法

df_all = pd.DataFrame([])

def func(year,month,day,hour,minute):
    #引数により、取得するデータを指定
    object_key_name = f'{year}/{month}{day}/{hour}/{minute}.json'
    #アクセスキー入力
    s3 = boto3.resource(
                    's3',
                    region_name='ap-northeast-1',
                    aws_access_key_id = 'xxx',
                    aws_secret_access_key = 'xxx',
                )

    bucket = s3.Bucket(bucket_name)
    obj = bucket.Object(object_key_name)
    response = obj.get()
    body = response['Body'].read()
    #取得したデータを格納
    data = json.loads(body.decode('utf-8'))

    df = pd.DataFrame.from_dict(data,orient='index').T
    global df_all
    df_all  = df_all.append(df)
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?