I'm trying to get the position of a dataframe from a list of dataframes, by using the built-in method index in python. My code is below:
df1 = pd.DataFrame([1, 2, 3])
df2 = pd.DataFrame([4, 5, 6])
df3 = pd.DataFrame([7, 8, 9])
dfs = [df1, df2, df3]
for df in dfs:
print(dfs.index(df))
Where instead of getting the expected 0, 1 and 2, it only returns 0, followed by ValueError:
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
I know this error typically comes from data frames comparison, and I've tried adding the .all() but to no avail.
If I change the list to something like a list of strings, ints or a mix of them, no problem whatsoever.
I've tried searching around but found nothing on this specific error.
I know I can easily add an extra variable that keeps on adding 1 for each iteration of the list, but I'd really like to understand what I'm doing wrong.