β

Python Pandas 排序

Waiting For You 202 阅读
    import pandas as pd  
      
    security = ['601318.XSHG','600036.XSHG','000333.XSHE','000651.XSHE','600660.XSHG','600887.XSHG','600004.XSHG','002415.XSHE','600519.XSHG','000002.XSHE','601166.XSHG','601006.XSHG']  
    stockSocre = [1,3,4,2,1,3,1,2,1,5,6,3]  
    dst_stocks = {}  
      
    i = 0  
    for stock in security:  
        score = stockSocre[i]  
        i = i + 1  
        dst_stocks[stock] = score  
    df = pd.DataFrame(dst_stocks.values(), index=dst_stocks.keys())  
    df.columns = ['score']  
    df = df.sort(columns='score', ascending=False)  
    print(df)  
    buyStockList = list(df.index)[:3]  
    print(buyStockList)

选取分数最高的3个股票

Python Pandas 排序

作者:Waiting For You
记录一些关于android,cocos2d-x,objective-c,mfc,directX,c++,数学的东西
原文地址:Python Pandas 排序, 感谢原作者分享。

发表评论