Pythonで為替レートをCSVファイルに書き出す

2018/6/10

$ sudo pip3 install pandas
$ sudo pip3 install pandas-datareader
$ sudo pip3 install matplotlib
# -*- coding:utf-8 -*-
#!/usr/bin/env python3


import datetime
import pandas
import pandas_datareader.data as web


if __name__ == '__main__':
    currency = {
	'ドル/円': 'DEXJPUS',
	'ユーロ/ドル': 'DEXUSEU',
	'ポンド/ドル': 'DEXUSUK',
    }

    start = datetime.datetime(2018, 3, 1)
    end = datetime.datetime(2018, 3, 31)

    data = web.DataReader(currency.values(), 'fred', start, end)
    data.columns = list(currency.keys())
    print(data)
    data.to_csv('currency.csv')
DATE ドル/円 ユーロ/ドル ポンド/ドル
2018-03-01 106.91 1.2216 1.3755
2018-03-02 105.65 1.2314 1.3769
2018-03-05 105.97 1.2329999999999999 1.3856
2018-03-06 106.03 1.2415 1.3886
2018-03-07 105.94 1.2397 1.3888
2018-03-08 106.08 1.2314 1.3824
2018-03-09 106.74 1.2326 1.3863
2018-03-12 106.52 1.2318 1.3898
2018-03-13 106.64 1.2398 1.3987
2018-03-14 106.17 1.2362 1.3946
2018-03-15 106.07 1.2321 1.3951
2018-03-16 106.1 1.228 1.3919
2018-03-19 105.83 1.2329 1.4032
2018-03-20 106.42 1.2271 1.4013
2018-03-21 106.3 1.2268 1.4064
2018-03-22 105.34 1.2309999999999999 1.4098
2018-03-23 104.83 1.236 1.4151
2018-03-26 105.0 1.244 1.4236
2018-03-27 105.72 1.2409999999999999 1.4161
2018-03-28 106.3 1.2351 1.411
2018-03-29 106.27 1.2297 1.4029
2018-03-30 106.2 1.232 1.4027