读取股票数据存储到本地MySQL数据库(二)

本文介绍如何通过凤凰API获取JSON数据,并利用Python处理数据,将股票信息转化为DataFrame,处理字符串类型的数据为float32类型,最终将数据存储到本地的MySQL数据库中。
摘要由CSDN通过智能技术生成

通过凤凰api获取到json数据。

#encoding = utf-8
import requests
import json
import pandas as pd

class GetStockPrice(object):

    def get_daily_price(self, stock):
        DAY_PRICE_URL = 'http://api.finance.ifeng.com/akdaily/?code=%s&type=last'
        url = DAY_PRICE_URL % stock
        columns = ['date', 'open', 'high', 'close', 'low', 'volume', 'chg', 'chg_percent', 'ma5', 'ma10', 'ma20', 'vma5',\
                   'vma10','vma20', 'turnover']
        response = requests.get(url)
        response.raise_for_status()
        response.encoding = 'utf-8'
        text = response.text
        js = json.loads(text)
        if js['record']:
            df = pd.DataFrame(js['record'], columns=columns)
        else:
            print('该条记录无数据࿰
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值