以正确的格式打印2d词典

时间:2019-02-25 19:25:28

标签: pandas csv dictionary nsepy

运行nsepy代码以从NSE获取数据

代码如下

startdate = datetime.date(2017,1,12)
expirydate = datetime.date(2017,1,19)
data = dict()

    for x in range(0,3):
        for y in range(1,8):
            startdate += datetime.timedelta(days=1)
            if ((startdate.weekday() !=5) and (startdate.weekday() !=6)):

                data [(x,y)] = get_history(symbol="BANKNIFTY",
                            start= startdate,
                            end= startdate,
                            index=True,
                            option_type='CE',
                            strike_price= int(df['CE Strike'][y]),
                            expiry_date=expirydate)

        expirydate += datetime.timedelta(days=7)
    outfile = open( 'dict.csv', 'w' )
    for key, value in sorted( data.items() ):
        outfile.write( str(key) + str(value))

输出作为图像附加。 所需输出的格式为

enter image description here    符号到期期权类型行使价开盘高低平仓最后结算价
   合约数溢价溢价未平仓合约的未平仓合约变动    基础

日期

0 个答案:

没有答案