Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python dataframe导出到excel中的市值_Python_Yfinance - Fatal编程技术网

Python dataframe导出到excel中的市值

Python dataframe导出到excel中的市值,python,yfinance,Python,Yfinance,错误如下 for symbol in stock: try: sector = yf.Ticker(symbol).info['sector'] name = yf.Ticker(symbol).info['shortName'] cap = yf.Ticker(symbol).info['marketCap'] except: sector = 'None' name = 'None' in

错误如下

for symbol in stock:
    try:
        sector = yf.Ticker(symbol).info['sector']
        name = yf.Ticker(symbol).info['shortName']
        cap = yf.Ticker(symbol).info['marketCap']
    except:
        sector = 'None'
        name = 'None'
    information[symbol,name,sector,cap] = web.get_data_yahoo(symbol, s,e)['Adj Close']
idx = pd.MultiIndex.from_tuples(information.columns)
information.columns = idx
  • 我还可以将以下信息输入到excel的数据框中吗?是字符和数字的结果数据的差异导致不同的python语言产生上述错误吗

    ['language','region','quoteType','triggerable','quoteSourceName', “货币”、“售前变更”、“售前变更百分比”, ‘上市前时间’、‘上市前价格’、‘定期市场变化’, “regularMarketChangePercent”、“regularMarketTime”、“regularMarketPrice”, “regularMarketDayHigh”、“regularMarketDayRange”、“regularMarketDayLow”, “regularMarketVolume”、“regularMarketPreviousClose”、“bid”、“ask”, “bidSize”、“askSize”、“fullExchangeName”、“financialCurrency”, “定期市场开放”,“平均每日交易量3个月”, “平均每日容积10天”、“52周以下变化”, “fiftyTwoWeekLowChangePercent”、“fiftyTwoWeekRange”, “fiftyTwoWeekHighChange”、“fiftyTwoWeekHighChangePercent”, “fiftyTwoWeekLow”、“fiftyTwoWeekHigh”、“dividendDate”, “earningsTimestamp”、“earningsTimestamp开始”、“earningsTimestamp结束”, “trailingannualdividentate”、“trailingPE”, “TrailingAnnualDividedield”、“marketState”、“EpstrailingTwevenmonths”, “epsForward”、“sharesOutstanding”、“bookValue”、“fiftyDayAverage”, “fiftyDayAverageChange”、“fiftyDayAverageChangePercent”, “TwoundredDayaAverage”、“TwoundredDayaAverageChange”, “百分之二百的平均变化率”、“市场上限”、“forwardPE”, “priceToBook”、“sourceInterval”、“exchangeDataDelayedBy”、“tradeable”, 'FirstTradeDateMills'、'priceHint'、'exchange'、'shortName', 'longName'、'messageBoardId'、'exchangeTimezoneName', “exchangeTimezoneShortName”、“GMTOFFSetName”、“market”, “esgPopulated”、“price”]


  • 引发异常时,您尚未定义
    cap='None'
    。添加它会改善它吗?
    [*********************100%***********************]  1 of 1 completed
    ---------------------------------------------------------------------------
    NameError                                 Traceback (most recent call last)
    <ipython-input-26-844c416a2200> in <module>
          7         sector = 'None'
          8         name = 'None'
    ----> 9     information[symbol,name,sector,cap] = web.get_data_yahoo(symbol, s,e)['Adj Close']
         10 idx = pd.MultiIndex.from_tuples(information.columns)
         11 information.columns = idx
    
    NameError: name 'cap' is not defined
    
    filename=r'C:\Users\User\Desktop\from_python\data_from_python2.xlsx'
    
    yeah = pd.read_excel(filename, sheet_name='entry')
    stock = []
    
    stock = list(yeah['name'])
    stock = [ s.replace('\xa0', '') for s in stock if not pd.isna(s) ]
    
    
    adj_close=pd.DataFrame([])
    high_price=pd.DataFrame([])
    low_price=pd.DataFrame([])
    volume=pd.DataFrame([])
    information=pd.DataFrame([])