How do I print/return the index of a particular value?
movies_per_year = pd.DataFrame(movies_per_year)
movies_per_year.columns = ["count"]
print(movies_per_year)
count
year
1891 1
1893 1
1894 2
1895 2
1896 2
1898 5
Here, my index is the year. I want to return all the indexes where count is 1. Furthermore movies_per_year.max() returns 5. So, it should return 1898.
Sign in to answer this question. The "min" and "max" functions in MATLAB return the index of the minimum and maximum values, respectively, as an optional second output argument.
The following code shows how to get the index of the max value in a one-dimensional NumPy array: The argmax () function returns a value of 2. This tells us that the value in index position 2 of the array contains the maximum value.
To lookup information related to the maximum value in a range, you can use a formula that combines the MAX, INDEX, and MATCH functions. In the example shown, the formula in I8 is: which returns the number 3920, representing the square footage (Sq. Ft.) of the most expensive property in the list.
Position of max value in list. To get the position of the maximum value in a range (i.e. a list, table, or row), you can use the MAX function together with the MATCH function. In the example shown, the formula in I5 is: = MATCH ( MAX ( C3:C11 ), C3:C11 , 0 ) Which returns the...
np.where()
- returns positional indices of the elements that satisfy the given condition:
In [31]: np.where(df['count'] == 1)[0]
Out[31]: array([0, 1], dtype=int64)
or
In [35]: np.nonzero(df['count'] == 1)
Out[35]: (array([0, 1], dtype=int64),)
if you need real index values (labels) instead of their positions:
In [40]: df.index[df['count'] == 1]
Out[40]: Int64Index([1891, 1893], dtype='int64', name='year')
to find an index of a maximum element:
In [32]: df['count'].idxmax()
Out[32]: 1898
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With