How to delete columns in a CSV file?

后端 未结 9 1717
你的背包
你的背包 2020-11-27 18:05

I have been able to create a csv with python using the input from several users on this site and I wish to express my gratitude for your posts. I am now stumped and will po

9条回答
  •  执笔经年
    2020-11-27 18:28

    It depends on how you store the parsed CSV, but generally you want the del operator.

    If you have an array of dicts:

    input = [ {'day':01, 'month':04, 'year':2001, ...}, ... ]
    for E in input: del E['year']
    

    If you have an array of arrays:

    input = [ [01, 04, 2001, ...],
              [...],
              ...
            ]
    for E in input: del E[2]
    

提交回复
热议问题