May-09-2019, 07:14 PM
Hello,
I am trying to run a function that creates additional columns in a data frame in case the column is missing.
The columns are for months. If the month is missing, the function should create an empty column for the missing month(s).
Below is what I have. However, the function stops once the first missing month is found. I would like it to run all the way to the end.
Can you see what I am missing? Thanks!
I am trying to run a function that creates additional columns in a data frame in case the column is missing.
The columns are for months. If the month is missing, the function should create an empty column for the missing month(s).
Below is what I have. However, the function stops once the first missing month is found. I would like it to run all the way to the end.
Can you see what I am missing? Thanks!
def add_column_missing(dataframe): if 'February'not in list(dataframe): return dataframe.assign(February='') elif 'March'not in list(dataframe): return dataframe.assign(March='') elif 'April'not in list(dataframe): return dataframe.assign(April='') elif 'May'not in list(dataframe): return dataframe.assign(May='') elif 'June'not in list(dataframe): return dataframe.assign(June='') elif 'July'not in list(dataframe): return dataframe.assign(July='') elif 'August'not in list(dataframe): return dataframe.assign(August='') elif 'September'not in list(dataframe): return dataframe.assign(September='') elif 'October'not in list(dataframe): return dataframe.assign(October='') elif 'November'not in list(dataframe): return dataframe.assign(November='') elif 'December'not in list(dataframe): return dataframe.assign(December='') else: print('done!') n = 12 while n > 0: n -= 1 return add_column_missing(grossadds_tableau)