Answer by cottontail for Python Pandas: Get index of rows where column...
Another method is to use pipe() to pipe the indexing of the index of BoolCol. In terms of performance, it's as efficient as the canonical indexing using [].1df['BoolCol'].pipe(lambda x: x.index[x])This...
View ArticleAnswer by Muhammad Yasirroni for Python Pandas: Get index of rows where...
For known index candidate that we interested, a faster way by not checking the whole column can be done like this:np.array(index_slice)[np.where(df.loc[index_slice]['column_name'] >=...
View ArticleAnswer by mbh86 for Python Pandas: Get index of rows where column matches...
If you want to use your dataframe object only once, use:df['BoolCol'].loc[lambda x: x==True].index
View ArticleAnswer by Carson for Python Pandas: Get index of rows where column matches...
I extended this question that is how to gets the row, columnand value of all matches value?here is solution:import pandas as pdimport numpy as npdef search_coordinate(df_data: pd.DataFrame, search_set:...
View ArticleAnswer by Ben Druitt for Python Pandas: Get index of rows where column...
Simple way is to reset the index of the DataFrame prior to filtering:df_reset = df.reset_index()df_reset[df_reset['BoolCol']].index.tolist()Bit hacky, but it's quick!
View ArticleAnswer by BENY for Python Pandas: Get index of rows where column matches...
First you may check query when the target column is type bool (PS: about how to use it please check link )df.query('BoolCol')Out[123]: BoolCol10 True40 True50 TrueAfter we filter the original df by the...
View ArticleAnswer by Surya for Python Pandas: Get index of rows where column matches...
Can be done using numpy where() function:import pandas as pdimport numpy as npIn [716]: df = pd.DataFrame({"gene_name": ['SLC45A1', 'NECAP2', 'CLIC4', 'ADC', 'AGBL4'] , "BoolCol": [False, True, False,...
View ArticleAnswer by unutbu for Python Pandas: Get index of rows where column matches...
df.iloc[i] returns the ith row of df. i does not refer to the index label, i is a 0-based index.In contrast, the attribute index returns actual index labels, not numeric...
View ArticlePython Pandas: Get index of rows where column matches certain value
Given a DataFrame with a column "BoolCol", we want to find the indexes of the DataFrame in which the values for "BoolCol" == TrueI currently have the iterating way to do it, which works perfectly:for i...
View Article