Python Forum
data validation with specific regular expression
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
data validation with specific regular expression
#1
This post is to find a way to check if data matches with specific regular expression

import pandas as pd 
 # Create first data frame
df1 = pd.DataFrame({
'key1': ['A', 'B', 'C', 'D', 'TST5 - 123'], 'key2': ['W', 'X', 'Y', 'Z' ,
'T2ST - 353'], 'value1': [1, 2, 3, 4, 'TST - 303'],  
'value2': [5, 6, 7, 8, 'TST - 103']})  

df2 = pd.DataFrame({
'key3': ['A', 'B', 'C', 'E', 'TST - 363'],  'key4': ['W', 'X', 'Z', 'Y' , 'TST - 373'],  
'value4': [9, 10, 11, 'A', 'TST - 123 - TST - 456 - TST -999'], 
'value5': [13, 14, 15, 16, 'TST - 109']})  

df1=df1.join(df2)
df1
data validation needs to be done on   the 5 column , the expected format is   "alphanumeric - number" or it could be "string - number" like valid values are : TST - 363, T2ST - 353, TST - 303, TST - 363,TST - 373 ..... in that case here the record that doesnt match the regular expression is - 'TST - 123 - TST - 456 - TST -999' This record should get outputted
Gribouillis write Jan-12-2024, 06:49 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.

Attached Files

Thumbnail(s)
   
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Regular Expression search to comment lines of code Gman2233 5 1,699 Sep-08-2022, 06:57 AM
Last Post: ndc85430
  How to extract specific data from .SRC (note pad file) Shinny_Shin 2 1,284 Jul-27-2022, 12:31 PM
Last Post: Larz60+
  List Creation and Position of Continue Statement In Regular Expression Code new_coder_231013 3 1,680 Jun-15-2022, 12:00 PM
Last Post: new_coder_231013
  Need help with my code (regular expression) shailc 5 1,944 Apr-04-2022, 07:34 PM
Last Post: shailc
  Regular Expression for matching words xinyulon 1 2,187 Mar-09-2022, 10:34 PM
Last Post: snippsat
  regular expression question Skaperen 4 2,514 Aug-23-2021, 06:01 PM
Last Post: Skaperen
  input data validation plumberpy 2 1,789 Aug-11-2021, 12:04 PM
Last Post: plumberpy
  How can I find all combinations with a regular expression? AlekseyPython 0 1,681 Jun-23-2021, 04:48 PM
Last Post: AlekseyPython
  Python Regular expression, small sample works but not on file Acernz 5 2,955 Jun-09-2021, 08:27 PM
Last Post: bowlofred
  Regular expression: cannot find 1st number in a string Pavel_47 2 2,430 Jan-15-2021, 04:39 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020