I have a usecase , where I m filtering on a row_key
which is being supplied as an argument
I m aware of the standard empty
property to check for a DataFrame
, however could not find a similar one for DataFrameGroupBy
Below is a code snippet that demonstrates the usecase , the data supplied is dummy -
import pandas as pd
from io import StringIO
df = pd.read_csv(StringIO("""
Name,Value,row_key,row_label
XYZ,100,abc,"Label - 2"
ASD,100,abc,"Label - 2"
GHJ,1000,abc,"Label - 2"
KLI,100,abc,"Label - 2"
BHY,1009,bnm,"Label - 2"
TGB,1409,bnm,"Label - 2"
YUJ,1509,bnm,"Label - 2"
KUT,1609,bnm,"Label - 2"
"""))
invalid_row_key = 'fgh'
filter_df = df[df['row_key'] == invalid_row_key].groupby('row_label')
#### I want something similar to below if case , to handle if the filter_df is empty
if filter_df.empty:
print("No Row Key Present")
I m aware I can use recent_index
on the grouped-dataframed , but I wanted to check if there is a better way of handling this