【发布时间】:2021-12-11 08:38:38
【问题描述】:
我有一个 csv 文件,如下所示:
Account Email User_Id User Type Base Role Last Login
123456 x@proton.com 111111 inter user 7
7891011 y@proton.com 222222 inter user 6
121314 z@proton.com 333333 inter user 5
还会有 50 行这样的其他行。每个帐户可以有多个用户。并且同一帐户可以在文件中多次列出。 我必须为每个帐户创建一个新的 csv 文件。 对于每个帐户,我必须选择整行并复制其内容。 我该怎么做? 如何选择:
for each account number
if a csv file for this account does not exist already
create a new file
copy the entire now and paste it in the new csv file
我可以用这个创建一个新的 csv 文件:
with open("test.csv") as fp
但我不知道如何选择每个帐号,然后将该行的内容复制并粘贴到新文件中。我是 Python 新手。请帮忙
【问题讨论】:
标签: python python-3.x csv file