import csv
import time

def timestamp_to_timestr(timeStamp):
    timeArray = time.localtime(int(timeStamp))
    otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
    return otherStyleTime

f=open('C:/look.csv','r')
reader = csv.DictReader(f)
headers = reader.fieldnames
look = list(reader)

f=open('C://up.csv','r')
up= list(csv.DictReader(f))
f.close()
for l in up:
    l['start_time'] = timestamp_to_timestr(l['start_time'])
    l['end_time'] = timestamp_to_timestr(l['end_time'])

for r in look :
    for s in up:
        if r['look_id'] == s['look_id'] and r['last_update_time'] >= s['start_time'] and r['last_update_time'] < s['end_time']:
            r['up_id'] = s['up_id']
            break


with open('C:/lookup.csv','w') as f:
    f_csv = csv.DictWriter(f, headers, lineterminator='\n')
    f_csv.writeheader()
    f_csv.writerows(look)

相关文章:

  • 2021-07-31
  • 2022-02-20
  • 2021-12-05
  • 2021-05-31
  • 2022-12-23
  • 2021-12-07
  • 2022-12-23
猜你喜欢
  • 2021-08-31
  • 2022-12-23
  • 2022-12-23
  • 2021-07-14
  • 2021-07-16
  • 2022-12-23
  • 2021-07-01
相关资源
相似解决方案