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 4612758
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:26:51+00:00 2026-05-22T01:26:51+00:00

Hi I have two CSV files as input, for example: file1 : AK163828 chr5

  • 0

Hi
I have two CSV files as input, for example:

file1 :

AK163828 chr5 s1 + e1 cttt 4
AK163828 chr5 s2 + e2 gtca 4
AK168688 chr6 s3 + e3 ggcg 4
AK168688 chr6 s4 + e4 tctg 4

file2 :

chr6s3+e3 ggcg
chr5s1+e1 cttt
chr6s4+e4 tata
chr5s2+e2 ggcg

#as you can see the file2 is randomly sorted

I want to compare column 1 of file2 with column 2, 3, 4, 5 merged of file1 and at the same time the column 2 of file2 with column 6 of file 1, and select only the matching lines.

The desired output is

chr6s3+e3 ggcg
chr5s1+e1 cttt

I tried to use this code:

import csv

reader1 = csv.reader(open(file1), dialect='excel-tab' )
reader2 = csv.reader(open(file2), dialect='excel-tab' )

     for row1, row2 in zip(reader1,reader2):
            F1 = row1[1] + row1[2] + row1[3] + row1[4] + '\t' row1[5]
            F2 = row2[0] + '\t' + row2[1]
            print set(F1) & set(F2)

But it doesn’t work. Can you help me to fix my code or give me an other way to do it?
Thanks for your help!

  • 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-05-22T01:26:51+00:00Added an answer on May 22, 2026 at 1:26 am

    Quick and dirty:

    import csv
    
    file1 = 'C:/Users/Me/Desktop/file1'
    file2 = 'C:/Users/Me/Desktop/file2'
    
    reader1 = csv.reader(open(file1))
    reader2 = csv.reader(open(file2))
    
    F1 = set(''.join(row1[0].strip().split()[1:6]) for row1 in reader1)
    F2 = set(''.join(row2[0].strip().split()) for row2 in reader2)
    
    for sequence in F1.intersection(F2):
        print(sequence[:-4]),
        print('\t'),
        print(sequence[-4:])
    

    Output:

    chr6s3+e3   ggcg
    chr5s1+e1   cttt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say that I have two CSV files (file1 and file2) with contents as shown
I have two DataTables, A and B , produced from CSV files. I need
I have tried the merge function to merge two csv files that I imported.
I have two data files in tab separated CSV format. The files are in
I have two files one is a tab delimited and one is a csv
I have 1000 CSV files from dfr.jstor.org with two columns, KEYWORDS and WEIGHT. The
I have two csv files: csv1 <- data.frame(y=c(classA, classB, classA, classB, classA, classC), DBID=c(d1,
I have two CSV files with a common column and I want to Join
I have the following PHP script which reads from two CSV files, At the
I have the following two implementation of reading csv files, the csv files in

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.