Sorry that this should probably be a comment, but I can't comment since my reputation is too low.
Since appending an empty dataframe seems like it might be a bit problematic (e.g. how long would you make it, and what would it contain? If it's just nans, how would that give any information about which query failed?), I will propose an alternative idea: if the query succeeds, add a column indicating the query's index from the list of queries:
import pandas as pd
df = pd.DataFrame()
for i, q in enumerate(list_of_querys):
try:
df_i = create_dataframes(q)
df_i['query'] = i
df = pd.concat([df, df_i])
except Exception as e:
pass
Then, you can run q_success = df['query'].unique()
to get the indices of the queries that succeeded, and q_failed = set(np.arange(len(list_of_querys))).difference(set(q_success))
to get the indices of the queries that failed.
Then you can access the queries directly via list_of_querys[index]
.
Alternatively, you can just create lists of the queries that succeeded/failed:
import pandas as pd
df = pd.DataFrame()
query_successes = []
query_failures = []
for i, q in enumerate(list_of_querys):
try:
df_i = create_dataframes(q)
df = pd.concat([df, df_i])
query_successes.append(i)
except Exception as e:
query_failures.append(i)
As a final note, in general you shouldn't just use except
, you should except specific exceptions (see here).