Currently I have a list of dataframes which I run through a list comprehension. The result is then all the dataframes with or without rows that qualify the function in the list comprehension. I would like to only print out the df's that are non-empty. Is that at all possible? In addition, would it be possible to print out the names of the dataframes as well?
Example:
N = 5
np.random.seed(0)
df1 = pd.DataFrame(
{'X':np.random.uniform(0,5,N),
'Y':np.random.uniform(0,5,N),
'Z':np.random.uniform(0,5,N),
})
df2 = pd.DataFrame(
{'X':np.random.uniform(-5,0,N),
'Y':np.random.uniform(-5,0,N),
'Z':np.random.uniform(-5,0,N),
})
def func_sel(df):
return df[df['X'] > 0]
dfs_list = [df1, df2]
dfs_sel = [func_sel(x) for x in dfs_list]
dfs_sel
Out[14]:
[ X Y Z
0 2.744068 3.229471 3.958625
1 3.575947 2.187936 2.644475
2 3.013817 4.458865 2.840223
3 2.724416 4.818314 4.627983
4 2.118274 1.917208 0.355180, Empty DataFrame
Columns: [X, Y, Z]
Index: []]
EDIT: What I need here is df1 shown only with 'df1' as a label of some sort.