checking for name of Pandas dataframe as a condition -


when want check pandas dataframe being called, how use dataframe name in if condition?

i keep getting "the truth value of dataframe ambiguous...." , can't figure out way around it.

df_even = pd.dataframe( data=[2,4,6,12,64,866,222]) df_prime = pd.dataframe( data=[5,7,11,13,17,19])  df_list = [df_even, df_prime]  frame in df_list:     if frame == df_even:         name = 'even'     elif frame == df_prime:         name = 'prime'     # dataframe next 

since you're testing identity, should use is opertator. note distinction between equality, i.e. logical values of 2 objects same, , identity, i.e. same object, i.e., 2 names refer same address in memory.

if frame df_even:     ... 

your original code isn't working because pandas overrides == operator perform value-by-value comparison (rather dataframe-level comparison). special override not returning boolean == ordinarily does.


more == vs is.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -