I have an application that will open many files and will convert these files into a pandas data frame. I want to ensure that all pandas’ data frames have the same structure so I want to create a warning if the number of the column is not equal that 10. I also want to know which file was the one that arise the warning.
How can I introduce the file_name into the warning message?
def load_data(self):
some code
file_name = file_name
if df.shape[1] !=10:
warning.warns("File_name is wrong"
return pandas_df2
>Solution :
you can use format strings as below
wrld = 'world'
A = 2
B = 5
print(f'Hello {wrld} {A + B} times')
output :
Hello world 7 times
pretty much anything in curly braces is python code