I need to create a function to check the length of a string in dataframe columns.
I have this code
df['XXX'] = df['XXX'].map(lambda x: x if isinstance(x, (datetime)) else None)
df_col_len = int(df['XXX']].str.encode(encoding='utf-8').str.len().max())
if df_col_len > 4:
print("In this step it will send a email")
The problem is that I have about 20 columns and each column should have a different length.
I need to check if the 1st column has max length <4, the 3rd column max length <50, the 7th column max length <47, etc. And then if a column does not meet the condition, write which column does not meet it.
Do you have an idea how to check the necessary columns at once?
Thanks