I use the following code to get a row from a dataframe and then find the max value.
def find_max(a):
return a.values.max()
row = df.iloc[0].astype(int)
max_value = find_max(a)
That works fine. However, if I pass an array like
ar = [1,2,3]
max_value = find_max(ar)
it doesn't work and I receive AttributeError: 'list' object has no attribute 'values'. How can I use that function for both types?
isinstance dataframe else max()?listis not generally referred to as an array. Pandas builds on top of numpy, which does have array type. You could usenumpy.max(), and test if.valuesexists.