Python Forum
Compare 2 Csv data sets, identify record with latest date
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Compare 2 Csv data sets, identify record with latest date
#5
I got this working, thanks:
import csv
import datetime

csv1 = ('c:\data\opt\csv1.csv')
csv2 = ('c:\data\opt\csv2.csv')
source = csv.reader(open(csv1,'rb'))
lookup = csv.reader(open(csv2,'rb'))

for data in lookup:
    lkeml = data[0]
    lkdt = datetime.datetime.strptime(data[1],"%d/%m/%y")
    for data1 in source:
        srceml = data1[0]
        srcdt = datetime.datetime.strptime(data1[1],"%d/%m/%y")
        if lkeml in srceml and lkdt > srcdt:
            print lkeml+"," +str(lkdt)
It identifies matches but the date includes time stamp even though it's not included in the formatting. I've had a look but can't find a specific method just for date, what am I missing?

source value:
[email protected], 2017/02/02
example output:
Output:
[email protected],2017-02-02 00:00:00
Thanks
Reply


Messages In This Thread
RE: Compare 2 Csv data sets, identify record with latest date - by MJUk - Dec-04-2017, 01:04 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to compare boxplot bw many data frames? vanphuht91 5 1,112 Jun-01-2023, 11:51 AM
Last Post: Larz60+
  Training a model to identify specific SMS types and extract relevant data? lord_of_cinder 0 1,013 Oct-10-2022, 04:35 AM
Last Post: lord_of_cinder
  replace sets of values in an array without using loops paul18fr 7 1,842 Jun-20-2022, 08:15 PM
Last Post: paul18fr
  Data sets comparison Fraetos 0 1,441 Sep-14-2021, 06:45 AM
Last Post: Fraetos
  Mann Whitney U-test on several data sets rybina 2 2,158 Jan-05-2021, 03:08 PM
Last Post: rybina
  Least-squares fit multiple data sets multiverse22 1 2,348 Jun-06-2020, 01:38 AM
Last Post: Larz60+
  How Do I Only Get the Year from Date and Isolate Data for Year? WhatsupSmiley 2 2,231 Apr-14-2020, 11:45 AM
Last Post: snippsat
  replace nan values by mean group by date.year, date.month wissam1974 5 8,604 Feb-19-2020, 06:25 PM
Last Post: AnkitGupta
  I am trying to change the value of an element in a record array ingu 1 2,218 Jan-14-2020, 01:30 PM
Last Post: perfringo
  Clustering for imbalanced data sets dervast 0 1,652 Sep-25-2019, 06:34 AM
Last Post: dervast

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020