将python搬回Django为雅虎财经服务

2024-04-25 22:03:18 发布

您现在位置:Python中文网/ 问答频道 /正文

嗨,我擅长Python,但我的Django技能是初学者。我在Tkinter中开发了一个程序作为GUI,但决定使用Django。你知道吗

这是我的后端和GUI:

from tkinter import*
import numpy as np
import pandas as pd
from scipy.stats import norm
from pandas_datareader import data as wb
from yahoofinancials import YahooFinancials

用户在输入字段中插入ticker并 这个变量通过tickers = [self.entry_stock.get()]帮助获得股票代码

然后我用下面的公式得到股票的价格

yahoo_financials = YahooFinancials(tickers)

new_data = pd.DataFrame()


        for t in tickers :new_data[t] = wb.DataReader(t, data_source ='yahoo', start = '2004-1-1')['Adj Close']


        a = new_data[t]

在Django中,我对如何将输入数据转换为索引符号感到困惑:

<form class="ticker_area form-control-lg" method="POST">
    {% csrf_token %}

    <input class="ticker_button"   type="text" placeholder="Ticker" aria-label="Search">
    <button class="btn btn-outline-warning btn-rounded btn-sm my-1" type="submit">OK</form>

在后端symbol= ['AAPL'],它允许以这种格式获取公司数据。在tkinter中,我使用了`tickers=[自营股票.get()]获取股票价值并进一步使用。你知道吗

但我不知道如何在Django中生成将tickers数据传递到此格式的窗体`tickers=[自营股票.get()]以便进一步使用它来获取股票价格

我在模板中使用了表单。我应该在哪里导入这些库?地址:

from tkinter import*
import numpy as np
import pandas as pd
from scipy.stats import norm
from pandas_datareader import data as wb
from yahoofinancials import YahooFinancials

我输入了views.py,但似乎不起作用。你知道吗

我会很感激从你那里得到指导,能够从搜索区域提取股票代码,并得到一些提示我应该寻找。任何帮助都将不胜感激。你知道吗


Tags: djangofromimportpandasdatagettkinteras