I am checking if a dataframe is empty or not but i want to do this in 1 line of code as i am checking many dataframe’s and don’t want to repeat the same code again as it becomes chunky. example is below. great if anyone can help
if not df.empty:
df['test_col'] = np.nan
else:
print('data is empty')
>Solution :
you can do a for loop:
list_of_dfs=[df1,df2,df3] # there can be any number of dfs
for x in list_of_dfs:
if not x.empty:
x['test_col'] = np.nan
else:
print('data is empty')