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

  • Home
  • SEARCH
  • 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 6109723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:26:11+00:00 2026-05-23T14:26:11+00:00

I have a tab delimited data text file in the following format: Depth Temp

  • 0

I have a tab delimited data text file in the following format:

Depth    Temp    Salinity
0.30    28.30    31.90
0.30    28.30    31.90
0.30    28.20    31.90
0.30    28.20    31.90
0.40    28.20    32.00
0.40    28.00    32.00
0.50    28.00    31.90
0.60    28.00    32.00
0.70    27.90    32.00
0.60    27.90    32.10

What I want to achieve is to obtain any lines where there are duplicate values in the Depth column and put them into a list/s. Then from that list/s I will average these values for each column (not averaging the Depth column), sort the values by Depth, and then output all this back into the original data file format. So in the example file above, the output would be:

Depth    Temp    Salinity
0.30    28.25    31.90
0.40    28.10    32.00
0.50    28.00    31.90
0.60    27.95    32.05
0.70    27.90    32.00

I understand I need to use .readlines() to grab the relevant lines, but how do I only grab duplicate lines?

Thanks in advance!

  • 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-23T14:26:11+00:00Added an answer on May 23, 2026 at 2:26 pm

    You should use a dictionary where the key is the depth.

    lines = [
    "0.30    28.30    31.90",
    "0.30    28.30    31.90",
    "0.30    28.20    31.90",
    "0.30    28.20    31.90",
    "0.40    28.20    32.00",
    "0.40    28.00    32.00",
    "0.50    28.00    31.90",
    "0.60    28.00    32.00",
    "0.70    27.90    32.00",
    "0.60    27.90    32.10"
    ]
    
    dict = {}
    for line in lines:
        depth, temp, salinity = map(float, line.split())
        old = (0,0,0)
        if depth in dict: old = dict[depth]
        dict[depth] = (old[0]+1, old[1]+temp, old[2]+salinity)
    
    for key in dict:
        tri = dict[key]
        print(str(key) +"   "+str(tri[1]/tri[0])+"   "+str(tri[2]/tri[0]))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to parse a tab-delimited text file with Ruby to extract some data
Let's say I have a tab-delimited text file that contains data arranged in columns
I have a .txt file with the following data: sampleF.txt --> (tab delimited) MSFT
I have the following data in a Tab delimited file: _ DATA _ Col1
I have a tab delimited text file as so : name \t loan period
I have a file in tab delimited format with trailing newline characters, e.g., 123
I have a text file with a large amount of data which is tab
I have a tab-delimited text file that I am parsing. Its first column contains
I have a bunch of text files with tab delimited data, like so X
Is there any script that would transform a tab delimited data file into libSVM

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.