一次返回所有变量 [英] return all the variables at once

查看:51
本文介绍了一次返回所有变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我正在做数据验证,如果所有的都满足我当前的代码,我想比较多个正则表达式条件变量

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 == 'POST':
        print(request.files['file'])
        f = request.files['file']
        data_xls = pd.read_excel(f)
        df2 = data_xls.reset_index()
        name_filter = df2[df2['Pensioner Name'].str.match('^[a-zA-Z\s\.]*$')]
        cnic_filter = df2[df2['CNIC'].str.match('^[\'][0-9+]{5}-[0-9+]{7}-[0-9]{1}[\']$')]
        wallet_filter = df2[df2['Wallet Account No'].astype(str).str.contains('^[0-9+]{8}$')]
        mobile_filter = df2[df2['Mobile Number'].astype(str).str.contains('^[3+][0-9+]{9}$')]
     return name_filter.to_html() 

我怎样才能一次返回所有变量来验证所有的正则表达式,现在它只返回 name_filter

how can i return all the variables at once validating all the regex now its only returning name_filter

谢谢

推荐答案

我试过了,它对我有用.虽然条件不满足.它仍然有效.

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!")

这篇关于一次返回所有变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆