I'm reading from an .ods file randomly selected cells. I randomly select them by the file loc(index).at('the column name')
I created this list [('L', 1), ('L', 6), ('L', 7), ('C', 1), ('C', 6), ('C', 7)] and put the second value into loc() and the first value into at().
I get the error below saying it needs to be an integer but when I print out the type() of the second value it says it is an integer.
I created this list [('L', 1), ('L', 6), ('L', 7), ('C', 1), ('C', 6), ('C', 7)] and put the second value into loc() and the first value into at().
I get the error below saying it needs to be an integer but when I print out the type() of the second value it says it is an integer.
def get_exercise(file, m_g):
df = pd.read_excel(file)
df_len = (len(df))
rand_nums = random.sample(range(0, df_len + 1), 3 )
ix_mg = [(mg, rn) for mg in m_g for rn in rand_nums]
pprint(ix_mg)
pprint(type(ix_mg[0][1]))
exercises = df.loc[ix_mg[0][1]].at[m_g[ix_mg[0][0]]]
pprint(exercises)returned valuesOutput:[('L', 1), ('L', 6), ('', 7), ('C', 1), ('C', 6), ('C', 7)]
<class 'int'>Error:Traceback (most recent call last):
File "/home/cspower/python_projects/D_Ex_R.py", line 49, in <module>
main()
File "/home/cspower/python_projects/D_Ex_R.py", line 45, in main
get_ex(file, m_g)
File "/home/cspower/python_projects/D_Ex_R.py", line 35, in get_ex
ex= df.loc[ix_mg[0][1]].at[m_g[ix_mg[0][0]]]
TypeError: list indices must be integers or slices, not str
