本文共 2076 字,大约阅读时间需要 6 分钟。
数据:
实例:
import requestspayload = { 'projectBean.startDate' : '2017-06-18', 'projectBean.endDate' : '2017-09-18', 'queryYN' : 'true'}response = requests.post('http://www.safe.gov.cn/AppStructured/view/project_RMBQuery.action', data=payload)html = response.text
import sqlite3 as dbwith db.connect('currency.sqlite') as con: df_rates.to_sql('currency_data', con=con, if_exists='replace', index=None)
from datetime import datetime, timedeltacurrent_time = datetime.now()for i in range(0, 300, 31): # 为了避免重复,range T - days T = 1 start_date = (current_time - timedelta(days = i + 30)).strftime('%Y-%m-%d') end_date = (current_time - timedelta(days = i)).strftime('%Y-%m-%d')
def get_currency(start, end): payload = { 'projectBean.startDate' : start, 'projectBean.endDate' : end, 'queryYN' : 'true' } response = requests.post('http://www.safe.gov.cn/AppStructured/view/project_RMBQuery.action', data=payload) html = response.text doc = pq(html) info = '
with db.connect('currency.sqlite') as con: df = pd.read_sql('select * from currency_data where currency = "美元"', con=con)
% pylab inlinedf.plot(kind='line', rot=30)
with db.connect('currency.sqlite') as con: df = pd.read_sql('select * from currency_data where currency in ("美元", "英镑")', con=con) df['date'] = pd.to_datetime(df['date'] ,format='%Y-%m-%d')df.info()