I will introduce how to return the index of the item that matches the condition from the data frame or series of pandas.
df.ix[[df.ix[:,0] == "hoge"],:].index[0]
df.ix[[df.ix[:,0] == "hoge"],:]
You probably know the syntax, but here I would like to describe how to return a pure index. By the way, the above syntax means "returns the row where column 0 is" hoge "".
The above result is returned in a pandas dataframe or series (dataframe if you are referencing a dataframe, series if you are referencing a series).
#Data frame
df.ix[[df.ix[:,0] == "hoge"],:]
#Column with the outermost ix:Since it is specified as multiple columns, the result will be returned in the data frame.
here,
df.ix[[df.ix[:,0] == "hoge"],:].index
If you try, the index of the data frame that matches the condition will be returned as it is. If multiple items meet the conditions, a series with a size larger than 1 will be returned.
Therefore,
df.ix[[df.ix[:,0] == "hoge"],:].index[0]
Then, you can get the index in a format that Python can handle as it is.
Recommended Posts