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)
添加表头,不是添加索引
最新推荐文章于 2023-02-13 19:03:58 发布