delete rows on a csv file depending on pattern python -


I am new to handle CSV files with Python and I want to write code which allows me to do the following: Pattern like: pattern = "3-5; 7; 10-16" (which may be different) and I want to delete (in that case) from 3 to 5, 7 and 10 16 lines one know how to do this?

You can not delete lines only from a CSV. Instead, you have to read it and then Must agree with the accepted values. The following code works:

  Import to CSV pattern = "3-5; 7; 10-16" off = [] in pattern.split (';'): if '-' I: off + = range (int (i.split ('-') [0]), int (i.split ('-') [1]) + 1) Other: off + = [int I)] with open ('test.txt') as f: reader = csv.reader (f) reader = [','. For the item (reader) if the i + 1 is not closed] in the print reader: reader with i (reader 'input.txt', 'w') for i: Reader for i2 : F2.write (i + '\ n')    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -