def my_function(df_1) : df_1 = df_1.filter[['col_1','col_2','col_3']] # Keeping only those records where col_1 == 'success' df_1 = df_1[df_1['col_1'] == 'success'] # Checking if the df_1 shape is 0 if df_1.shape[0]==0: print('No records found') break #further program
I am looking to break the execution of further program if the if condition is met.
is this the correct way to do so..? since break only ends the loop, but i want to end the function
Advertisement
Answer
You need to use
if df_1.shape[0]==0: print('No records found') return