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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:59:10+00:00 2026-06-10T15:59:10+00:00

I am reading a csv line by line. The CSV looks like this: 29.781646

  • 0

I am reading a csv line by line. The CSV looks like this:

29.781646
29.781646
42.698079
43.346914
44.369203
45.006459
45.006459
39.316758

When two numbers are exactly the same I would like to change one slightly.

For example there are two values that are 29.781646 and I would like to change one to be 29.781645

If the csv contains:

29.781646
29.781646
29.781646

then I would like to change it to:

29.781646
29.781645
29.781644

I would very much appreciate your guidance, on implementing this efficiently.

Please note that I want to do this in multiples of 0.000001

  • 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-10T15:59:11+00:00Added an answer on June 10, 2026 at 3:59 pm

    You could just iterate over the file line by line, and keep track of seen values using a set, decreasing the value if it is already in the set.

    rough example:

    seen = set()
    with open('test.csv') as input, open('test_out.csv', 'w') as output:
        for line in input:
            value = float(line)
            while value in seen:
                value -= 0.000001
            seen.add(value)
            output.write(str(value) + '\n')
    

    This is efficent since a set offers a O(1) lookup


    If you’re going to write the values back to the same file anyway, you can use the fileinput module:

    import fileinput
    
    seen = set()
    for line in fileinput.FileInput('test.csv', inplace=True):
        value = float(line)
        while value in seen:
            value -= 0.000001
        seen.add(value)
        print str(value).strip()
    

    EDIT

    To address eumiro’s comment about the floating point issue:

    You can use the decimal modules Decimal or just multiply/divide the value with/by 1000000 to work with int instead of using float. As I wrote, this is just a rough example 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my iPhone app, I'm reading a csv file. The relevant line is this:
I'm reading a .csv file that was created in Excel with the first line
So I'm reading a CSV file with two columns, and then taking the product
I am reading a CSV file and I would like to cache the results
I am reading in a csv file and dealing with each line as a
I am trying to read a CSV file containing a line like following: test,"test,"test,test,test,test
I am reading a csv file using opencsv. I am ignoring the first line
I am reading each line of a CSV file and need to get the
i am reading a csv file line by line here: def GetDistinctValues(theFile, theColumn): lines=theFile.split('\n')
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.