我使用以下命令来获取max元素:
print("%.2f" % total_returns['return 5 days ago'].max(), total_returns['return 5 days ago'].idxmax(), "5 days max")有没有办法也能得到第二,第三等最大的?
total_returns.head()
Out[15]:
first close last close ... date 1250 days ago date 1500 days ago
S&P 500 1469.25 2893.06 ... 2014-10-20 2013-10-22
Tesla 23.89 327.71 ... 2014-11-07 2013-11-11
Apple 3.67188 249.05 ... 2014-11-07 2013-11-11
Microsoft 58.375 144.19 ... 2014-11-07 2013-11-11
Amazon 76.125 1777.08 ... 2014-11-07 2013-11-11
[5 rows x 47 columns]发布于 2019-10-29 16:07:07
我猜您正在使用pandas.DataFrame。
在这种情况下,您可以使用pandas.DataFrame.nlargest
n=3
total_returns.nlargest(n, 'return 5 days ago')https://stackoverflow.com/questions/58603148
复制相似问题