So I have the following pandas dataframe query:
has_primary_reopen = market_info.loc[before_primary_close, "market_state"].iloc[-1] == 'CTS'
For the above, I am getting an indexing error, because
market_info.loc[before_primary_close, "market_state"]
returns an empty dataframe.
So I want to add an if statement to check that if the above returns an empty dataframe, then don’t execute the top query.
Is this possible?
>Solution :
Yes, you can do it like this:
if not market_info.loc[before_primary_close, "market_state"].empty:
has_primary_reopen = market_info.loc[before_primary_close, "market_state"].iloc[-1] == 'CTS'