import csv
import os
import time

import numpy as np
import pandas as pd
data= pd.read_csv('./集合竞价数据.csv')

data= data.groupby('日期')
with open('./'+'buyRate前10'+'.csv','w',encoding='gbk',newline='') as csfile:
    writer = csv.writer(csfile)
    writer.writerow(['代码', '日期', '昨日成交量', '昨日成交额', '昨日换手率', '10日涨幅', '流通市值','开盘价','明日开盘价','涨幅','盈利','价格','totalBuyVol'	,'totalBuyAmount','cancelBuyVol','cancelBuyAmount','preBuyVol','cirVol','rate','buyRate','cancelRate'])
    for index,iter in data:
        iter=iter.sort_values("buyRate",ascending=False)
        iter=iter.iloc[0:10]
        for i, item in iter.iterrows():
            writer.writerow([item['代码'],
                             item['日期'],
                             item['昨日成交量'],
                             item['昨日成交额'],
                             item['昨日换手率'],
                             item['10日涨幅'],
                             item['流通市值'],
                             item['开盘价'],
                             item['明日开盘价'],
                             item['涨幅'],
                             item['盈利'],
                             item['价格'],
                             item['totalBuyVol'],
                             item['totalBuyAmount'],
                             item['cancelBuyVol'],
                             item['cancelBuyAmount'],
                             item['preBuyVol'],
                             item['cirVol'],
                             item['rate'],
                             item['buyRate'],
                             item['cancelRate']


                             ])

