Difference between NULL, empty and blank Python

2

I am making a Data Quality that receives a list with data from a Database and I have two rules:

  • Null fields: Fields that are filled with the word NULL
  • Blank / empty fields: Fields that come in blank or empty
  • For the NULL rule I am using:

    if (pd.isnull(lista[linha2][linha])):
        print("Alguma coisa")
    

    and recognizes the field as NaN .

    How do I do blank or empty fields?

    And does the field type influence (ex: str and float)?

        
    asked by anonymous 15.05.2017 / 18:26

    1 answer

    3

    In Python, if you just do

    if variavel:
        ...
    

    Any value that is analyzed as true will pass the test. It was not very clear, at least to me, what this object would be pd that you execute the method isnull , if it is Pandas it will in fact be checked if the value is None or NaN . Without the Pandas, it could be done:

    if lista[linha2][linha] is None:
        ...
    

    For NaN values:

    import math
    
    if math.isnan(lista[linha2][linha]):
        ...
    

    For blank fields you will possibly receive an empty string, then:

    if lista[linha2][linha] == "":
        ...
    
        
    15.05.2017 / 19:16