0

嗨,我有一个带引号的句子的 csv,我想省略任何不超过三个单词的句子,并将其逐行复制到另一个 csv。高度赞赏所有帮助。谢谢

Input csv:

"9795e7dc9a5b032bdb39ace56c08b0e1","Top     Gear","FC Barcelona","Making code names so people dont know who your talking about","Audi A5","Ice cream","Wentworth Miller","Bob Marley","Megan Fox","FIFA","ShootandGoal","Eminem","Nike","Manchester United","Pilotta"
"650c7b5f671972947ef34de59a8e9dd3","Tioga Downs Casino","Ryan Gosling","Crazy, Stupid, Love.","Jane Eyre","Boycott Nike for Resigning Michael Vick"

 Output csv:
 "9795e7dc9a5b032bdb39ace56c08b0e1","Top     Gear","FC Barcelona","Audi A5","Ice cream","Wentworth Miller","Bob Marley","Megan Fox","FIFA","ShootandGoal","Eminem","Nike","Manchester United","Pilotta"
"650c7b5f671972947ef34de59a8e9dd3","Tioga Downs Casino","Ryan Gosling","Jane Eyre"
4

1 回答 1

0

一些东西(注意,这可能需要稍微编辑,但你在你的问题中没有给出代码),比如:

newfile = open(newfilename,"w")  
oldfile = open(oldfilename).readlines()


for line in oldfile:
  items = line.split(",")#gets each quoted thing
  for i in items:
      subitems = i.split() #will return a list of each word inside each quoted thing
      if len(subitems) <= 2:
          newfile.write(i + ",")


newfile.close()
于 2014-05-14T03:12:02.583 回答