loop through rows of one csv file to find corresponding data in another

后端 未结 3 1876

I got an interesting problem:

file1.csv has a few hundred rows like:

Code,DTime
1,2010-12-26 17:01
2,2010-12-26 17:07
2,2010-12-26 17:15
3条回答
  •  伪装坚强ぢ
    2020-12-06 21:21

    you can create a dictionary from file2, where the key is the prefix of the time you want, and the value is either first row, or all the rows matching this prefix. then it's simply a matter of doing something like:

    entries = file2Dict.get(file1Entry)
    if entries:
       print  "First entry is %s" entries[0]
    

提交回复
热议问题