'Assertion none when checking column names of a dataframe
I want to check that the columns of my data frame are in the right order. I used this code
def validation_columns(self)
header_input = list(self.data.columns)
assert header_input == ['column1','column2'], log.log_message("ERROR:...")
# log.log_message() is a function to print info in a log.txt file
Why do I get the error
AssertionError: None
Solution 1:[1]
The second argument to the assert keyword is not code to be run in the case of a False condition, it is a message to display in the case of a False condition. Because the function log.log_message(...) does not return anything, None is printed.
If you want to print text to a file if the condition is False, just use a normal if statement:
def validation_columns(self):
header_input = list(self.data.columns)
if header_input != ['column1','column2']:
log.log_message("ERROR:...")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Lecdi |
