Python 意外程序故障-2
我有一张股票行情表。这些信息来自雅虎财经。 我的Python代码计算每个项目的每日收入/损失百分比 并显示最高的五个标记 我面临的问题是:Python 意外程序故障-2,python,list,Python,List,我有一张股票行情表。这些信息来自雅虎财经。 我的Python代码计算每个项目的每日收入/损失百分比 并显示最高的五个标记 我面临的问题是: 当股票行情日百分比以0%结束时 当雅虎呈现一张空白(黑色)图表时 在这两种情况下,程序通过try/except终止打印:“错误,其中一个标记为0%” 是否可以终止程序或绕过错误并打印导致错误的股票代码名 非常感谢 丹尼尔 代码如下: !!pip安装ffn import ffn import pandas as pd import numpy as np im
import ffn
import pandas as pd
import numpy as np
import time
import traceback
from matplotlib import pyplot as plt
plt.style.use('fivethirtyeight')
#from scipy.stats import norm
%matplotlib inline
start = time.perf_counter()
tickers = ['A','AA','AACG','AAL','AAME','AAN','AAON','AAP','AAPL','AAT','AAWW','AAXN','AB','ABBV','ABC','ABCB','ABEV','ABG','ABEO','ABIO',]
try:
df = ffn.get(tickers, start='04/30/2020',end='12/31/2020').to_returns().dropna()
#ticker_error = tickers.pop()
#print(ticker_error)
sums = df.select_dtypes(pd.np.number).sum()
sort_sums = sums.sort_values(ascending = False)
print(df.shape)
finish = time.perf_counter()
print(f'Finished in {round(finish - start,2)}second(s)')
print('---------------')
print('% RETURN')
print('---------------')
print(sort_sums.as_format('.2%').head(40))
except:
ticker_error = tickers.pop()
print(ticker_error)
print('One of the tickers is ZERO %')
pass
使用
while
循环继续处理同一代码,并在Variable中保持当前加工库存和after except语句中打印该名称或标识您可以进一步帮助吗?…在Variable中保持当前加工库存和after except语句中打印该名称或标识该名称”。请详细说明你能在我的代码上给我看你的答案吗?使用while
循环继续处理相同的代码,在Variable中保持当前加工库存,在after except语句中打印该名称或标识,你能进一步帮助吗?“…在Variable中保持当前加工库存,在after except语句中打印该名称或标识”.请详细说明你能在我的密码上给我看你的答案吗?