Try to search your question here, if you can't find : Ask Any Question Now ?

How to find the index of the max value of pandas data array

HomeCategory: stackoverflowHow to find the index of the max value of pandas data array
Avatarcraig asked 2 weeks ago

With a dataFrame parsed into pandas.
The user can get the index (column) name of maximum value using DataFrame.idxmax
However, if all the values in the row are zero (or of equal value), then the index returns the first column by default.

Therefore, how can one filter for all equal values so that no column name is returned.

I am using pandas.DataFrame.idxmax help files.
However, there is no filter option.

I believe that one can filter in pandas using a loc[df['something']==value], but i am not sure how to do this for the max value.

import pandas as pd
myArr = {'column0':[1, 1, 0, 1, 1], 
    'column1':[1, 2, 0, 4, 5], 
df = pd.DataFrame(myArr)

m = df.idxmax(axis=1)

actual result:

0    column3
1    column3
2    column0
3    column3
4    column3

The value in the second row defaults to the first column because the values are zero (or equal).

How can this be filtered out ?

1 Answers
Best Answer
AvatarMannu answered 2 weeks ago
Your Answer

19 + 9 =

Popular Tags

WP Facebook Auto Publish Powered By :