Regex for replacing missing value period

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Endkill Emanon
    New Member
    • Dec 2010
    • 9

    #16
    Code:
    # newline1=line.replace('.,','')
    # newline2=newline1.replace(',.\n','') #incase last value is a period
    This code works. The only problem is a float that is an int... e.g in C# and C++ you values like 100f == (float)100 == 100.0, which could be in your db as ",100.,".

    Your second replace deletes the field and mashes the rows together screwing the db. Try instead....
    Code:
    # newline1=line.replace('.,','')
    # newline2=newline1.replace(',.\n',',0.0\n') #incase last value is a period
    (I don't know about python but in c, c++ and c# you can chain code together like... "temp=line.repl ace('.,','').re place(',.\n',', 0.0\n')". To me its easier to think this way.)

    Comment

    • akselo
      New Member
      • Sep 2007
      • 21

      #17
      Thanks all for your help. I must say that it makes sense to just use the built-in split-to-list feature of strings and check each element. It seems pretty safe. However, it takes a long time to process a large dataset and check each value to see if it is a period, in this case the census numbers for the state of California. But efficiency doesn't matter that much in this case as releases are rare.

      Comment

      • dwblas
        Recognized Expert Contributor
        • May 2008
        • 626

        #18
        it takes a long time to process a large dataset and check each value to see if it is a period
        Only do that if it is necessary, i.e. if you are summing one field of the list for example, check for a "." and ignore (since it is zero). When you are already iterating through the list it takes an insignificant amount of time since it is one additional if() statement. You do not have to change every field, just check the ones you are using.

        Comment

        Working...