Find the order position of a particular value in the pandas dataframe?

Asked 2 years ago, Updated 2 years ago, 13 views

import pandas as pd


a = pd.DataFrame({'value': [0, 1, float('nan'), 3, 4, float('nan')]

I would like to find a location with the nan value in a above. indexWithout using the value

First of all, a['value'].Find the nan value with isnull() I'm trying to find the location (order) where the nan value is located, but I don't know how to find the last location. Of course, I can make the code complicated, but it's getting too long, so I'm asking if there's a simple way.

python

2022-09-20 21:38

1 Answers

It's the last one with iloc.If it's too long, I don't have to say.

a[a['value'].isnull()].iloc[-1]


2022-09-20 21:38

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.