Skip to content Skip to sidebar Skip to footer

Return All The Variables At Once

hey i am working on data validation and want to compare multiple regex conditions variable if all satisfies my current codes goes like this def upload_file(): if request.method

Solution 1:

Basically you are not validating one result but all results and filtering them out.

So assuming that you want all the results to pass and be true and the case where they are all true.

# COMPARE IF THE SAME DATASETS ARE PRESENT, EVEN AFTER PASSING ALL THE CONDITIONS AS TRUEif df2[df2['Pensioner Name'].str.match('^[a-zA-Z\s\.]*$'].equals(df2['Pensioner Name'])     and df2[df2['CNIC'].str.match('^[\'][0-9+]{5}-[0-9+]{7}-[0-9]{1}[\']$'].equals(df2['CNIC'])     and df[df2['Wallet Account No'].astype(str).str.contains('^[0-9+]{8}$'].equals(df2['Wallet Account No'].astype(str)) and  df2[df2['Mobile Number'].astype(str).contains('^[3+][0-9+]{9}$')].equals(df2[['Mobile Number'].astype(str)):
    return df2.to_html()
else:
    return'''<h2> Error in data </h2>'''

Solution 2:

I tried this and it works for me. Although the condition was not satisfied. It still works.

import pandas as pd

df2 = pd.DataFrame(
    {'Pensioner Name' : ['CHANESER','CHANESERS'],
     'CNIC' : ['41207-0800205-9','41207-0800205-9'],
     'Wallet Account No' : ['BDS00229','BDS00229'],
     'MobileNumber' : ['3203501312','3203501312']
     }
)



if df2[df2['Pensioner Name'].str.match('^[a-zA-Z\s\.]*$')].equals(df2['Pensioner Name']) and \
df2[df2['CNIC'].str.match('^[\'][0-9+]{5}-[0-9+]{7}-[0-9]{1}[\']$')].equals(df2['CNIC'])and \
df2[df2['Wallet Account No'].astype(str).str.contains('^[0-9+]{8}$')].equals(df2['Wallet Account No'].astype(str)) and \
df2[df2['Mobile Number'].astype(str).contains('^[3+][0-9+]{9}$')].equals(df2['Mobile Number'].astype(str)):
    print("works!")
else:
    print("not works!")

Post a Comment for "Return All The Variables At Once"