开发者

How to differentiate between datatypes of columns of dataframe and validate them?

开发者 https://www.devze.com 2022-12-07 18:44 出处:网络
Here in for loop I have tried to get col 1 by 1 and 开发者_如何学运维 if its data type is integer - passed to validate the data by calling is_Datanumeric function

Here in for loop I have tried to get col 1 by 1 and

开发者_如何学运维
  • if its data type is integer - passed to validate the data by calling is_Datanumeric function

  • else any else data type(string) - passed to valdate the data by calling isDataaplha function

    def is_Data_alpha(ch):
        if ch.rlike(obj['char_exp']):
            return 0
        else:
            return obj['in_valid']
    
    
    def is_Data_numeric(ch):
        if ch.isNotNull():
            return 0
        else:
            return obj['in_valid']
    
    
    for x in df1.columns:
        if dict(df1.dtypes)[x] == 'int':
            re = is_Data_numeric(x)
            print(re)
        else:
            re = is_Data_alpha(x)
            print(re)
    

But got an error :

Traceback (most recent call last):
  File "/home/zmo-ubt-preetim-01/PycharmProjects/pythonProject/script1.py", line 41, in <module>
    re = is_Data_numeric(x)
  File "/home/zmo-ubt-preetim-01/PycharmProjects/pythonProject/script1.py", line 32, in is_Data_numeric
    if ch.isNotNull():
AttributeError: 'str' object has no attribute 'isNotNull'
sys:1: ResourceWarning: unclosed file <_io.TextIOWrapper name='inputVariables.json' mode='r' encoding='UTF-8'>

I want to validate data by their data types.

0

精彩评论

暂无评论...
验证码 换一张
取 消