I wanted to see the methods available for a pandas object. When I ran this code I got an AttributeError error. I\'ve searched but not found an example of this error or how t
Okay the problem of your code is how u are iterating the result of group by.
This answer shows how to iterate properly.
This code shows how to do your task:
import pandas as pd
def method1():
return 0
exampleDf = pd.DataFrame(columns=["name","group","failed"])
exampleDf.loc[0] = ["method1", "failed", 1]
exampleDf.loc[1] = ["method2", "success", 0]
exampleDf.loc[2] = ["method3", "success", 0]
exampleDf.loc[3] = ["method4", "failed", 1]
groupedDf = exampleDf.groupby(['group', 'failed'])
for params, table in groupedDf:
print("Iterating over the table with the params: " + str(params) )
print("Table: \n" + str(table))
for index, row in table.iterrows():
if(row['name'] in dir()):
print("The method " + str(row['name']) + " is defined.")
Output:
Iterating over the table with the params: ('failed', 1)
Table:
name group failed
0 method1 failed 1
3 method4 failed 1
The method method1 is defined.
Iterating over the table with the params: ('success', 0)
Table:
name group failed
1 method2 success 0
2 method3 success 0