Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Changing all values at one CSV

I want to be able to change all values that meet the condition as one. This moment in time I do one value at the time. It might be more than one value that meet the condition, but it need to be change differently.

Let say value x and value y meet the condition and value x is change to x1 and value y to y1. What I’m trying to do is changing all appearance of value x at one time and all appearance of value y at one time

all_rows = []    
for row in all_rows:
        some_num = row[0]
        if strformat.match(some_num):
            continue
    
        change = input(f"\n'{some_num}' doesn't match, change it to: ")
        row[0] = change.strip()

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You could keep track of changes already given by the user in a dictionary and prompt when a new change is needed.

all_rows = []    
changes = {}
for row in all_rows:
        some_num = row[0]
        if strformat.match(some_num):
            continue
        try:
            row[0] = changes[some_num]
        except KeyError:
            change = input(f"\n'{some_num}' doesn't match, change to: ")
            change = change.strip()
            changes[some_num] = change
            row[0] = change
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading