Check whether pattern is in csv field and output into a different file (whole row containing said pattern)
I want to search through a csv file, a particular column (code) for specific pattern(s).
For example
I would like to use python to extract rows 1 and 2 given they have the pattern '[0-9][0-9][A-Z]' in the column code
but the last row does not adhere to the above so I would like to negate it and output it into a different csv; and output the criteria that is satisfied onto a new csv.
Other patterns need to be included as well and may be present within the data so this is why I wanted to add it to a list variable and check the pattern that way. For instance a code critera could be '[0-9][0-9][A-Z] [0-9][0-9][A-Z]'. Wonder if it would be best to go with perhaps regex however with a list I feel if there are additional patterns to include or required this can then be added to said list?
source https://stackoverflow.com/questions/76291647/check-whether-pattern-is-in-csv-field-and-output-into-a-different-file-whole-ro
Comments
Post a Comment