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?
>Solution :
def find_max(a):
if isinstance(a, list):
return max(a)
elif isinstance(a, pd.DataFrame):
return a.values.max()
else:
print("No max method found for the input type")