为了账号安全,请及时绑定邮箱和手机立即绑定

读取数据帧的困难

读取数据帧的困难

至尊宝的传说 2021-06-29 17:14:10
我有一个 csv 文件,如下所示:[8:3:1978] LOG [Sale:internals.py:makeSaleEntry:0] Entered with productid= 2327, storeid= 146, No.OfUnits= 1[19:1:2007] LOG [Sale:internals.py:makeSaleEntry:1] Entered with productid= 1908, storeid= 202, No.OfUnits= 11[22:4:2001] LOG [Sale:internals.py:makeSaleEntry:2] Entered with productid= 3072, storeid= 185, No.OfUnits= 16[22:12:1915] LOG [Sale:internals.py:makeSaleEntry:3] Entered with productid= 1355, storeid= 177, No.OfUnits= 1[19:8:1963] LOG [Sale:internals.py:makeSaleEntry:4] Entered with productid= 2235, storeid= 35, No.OfUnits= 16[16:11:1997] LOG [Sale:internals.py:makeSaleEntry:5] Entered with productid= 1439, storeid= 141, No.OfUnits= 26我已经使用数据帧 df 读取了该文件。df = pd.read_csv('a.txt')我想逐行访问数据框并在另一个 csv 文件中打印 productid、storeid 和 No.OfUnits,如下所示:2327,146,11908,202,113072,185,161355,177,12235,35,161439,141,26我的一段代码是:for i, row in df.iterrows():    strr = ""    for j, column in row.iteritems():        seq = column.split('= ')        strr = strr + seq[1] + ","    file = open("a.csv", "a")    file.write(strr[:-1]+"\n")    file.close()这段代码工作正常,只是它忽略了写第一行 (2327,146,1)。请提出更改建议。
查看完整描述

3 回答

  • 3 回答
  • 0 关注
  • 153 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号