添加表头,不是添加索引

list1 = df.x2
file = "C:/Users/Administrator/Desktop/连续3天 0商机.csv"
with open(file, 'w', newline='') as f:
    fieldnames = ['门店名称','日期','人数','商机量','查看次数','二手带看量','人均商机量','人均查看次数']
    writer = csv.DictWriter(f,fieldnames=fieldnames)
    writer.writeheader()
    
    for i in range(len(list1) - 2):
        if list1[i] + list1[i + 1] + list1[i + 2] == 0:
        # if list1[i] > 3 and list1[i + 1] > 3 and list1[i + 2] > 3:
            for j in range(2):
                index = [str(df.name[i + j]), str(df.date[i + j]), str(df.x1[i + j]), str(df.x2[i + j]),str(df.x3[i + j]),str(df.x4[i + j]),
                         str(df.y1[i + j]),str(df.y2[i + j]),"\n"]
                print(index)
                str1 = ",".join(index)      # 列表list 改为 字符串str        --文本      ,csv
#                 file = "C:/Users/Administrator/Desktop/连续3天0商机try.csv"
#                 with open(file, 'a') as f:
                f.write(str1)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值