Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7717357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:52:39+00:00 2026-06-01T02:52:39+00:00

I got an interesting problem: file1.csv has a few hundred rows like: Code,DTime 1,2010-12-26

  • 0

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

file2.csv has about 11 million rows like:

id,D,Sym,DateTime,Bid,Ask
1375022797,D,USD,2010-12-26 17:00:15,1.311400,1.311700
1375022965,D,USD,2010-12-26 17:00:56,1.311200,1.311500
1375022984,D,USD,2010-12-26 17:00:56,1.311300,1.311600
1375023013,D,USD,2010-12-26 17:01:01,1.311200,1.311500
1375023039,D,USD,2010-12-26 17:01:02,1.311100,1.311400
1375023055,D,USD,2010-12-26 17:01:03,1.311200,1.311500
1375023063,D,USD,2010-12-26 17:01:03,1.311300,1.311600

What i’m trying to do is to write a script that takes each DTime value in file1.csv and finds the first instance of a partial match in the DateTime column of file2.csv, and outputs DateTime, Bid, Ask for that row. The partial match is on the first 16 characters.

Both files are sorted from oldest to newest, so if “2010-12-26 17:01” from file1.csv matched 4 entries in file2.csv, I only need to extract the first one: “2010-12-26 17:01:01”

Not sure how to proceed.. I tried a dictionary but the order of values is important so i’m not sure if that would work. Maybe bring file1’s DTime column into a list and for each entry in that list search DateTime in file2?

Thanks guys

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T02:52:40+00:00Added an answer on June 1, 2026 at 2:52 am

    If you don’t have duplicate DTime values, this should work:

    import csv
    
    file1reader = csv.reader(open("file1.csv"), delimiter=",")
    file2reader = csv.reader(open("file2.csv"), delimiter=",")
    
    header1 = file1reader.next() #header
    header2 = file2reader.next() #header
    
    for Code, DTime in file1reader:
        for id_, D, Sym, DateTime, Bid, Ask in file2reader:
            if DateTime.startswith(DTime): # found it
                print DateTime, Bid, Ask   # output data
                break                      # break and continue where we left next time
    

    Edit

    import csv
    from datetime import datetime
    
    file1reader = csv.reader(open("file1.csv"), delimiter=",")
    file2reader = csv.reader(open("file2.csv"), delimiter=",")
    
    header1 = file1reader.next() #header
    header2 = file2reader.next() #header
    
    for Code, DTime in file1reader:
        DTime = datetime.strptime(DTime, "%Y-%m-%d %H:%M")
        for id_, D, Sym, DateTime, Bid, Ask in file2reader:
            DateTime = datetime.strptime(DateTime, "%Y-%m-%d %H:%M:%S")
            if DateTime>=DTime: # found it
                print DateTime, Bid, Ask   # output data
                break                      # break and continue where we left next time
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got an interesting time-travel problem today, using the following code: for (int i
I've got an interesting problem. I have an iPad App which has to parse
I've got an interesting problem that I'd like some advice and opinions on if
I've got an interesting box-model problem here. I have a header full of links,
I ran into an interesting problem at work today. I got a request to
I've got an interesting problem that's cropped up in a sort of pass based
Ok, I've got an interesting problem here. I have two tables, tips and votes.
I have got a weird problem here, and more interesting that it works fine
So I've got an interesting problem that I need help with faster than I
Ok I've got a bit of an interesting problem on my hands. Here's a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.