<jupyter_start><jupyter_text>How to pull out (index,column) pair based on the value<jupyter_code>import pandas as pd
import numpy as np
df = pd.DataFrame(data=np.random.random([4,5]),
                 index=['index{}'.format(i) for i in range(4)],
                 columns=['column{}'.format(j) for j in range(5)])
df<jupyter_output><empty_output><jupyter_text>we want to pull out all (index-column) pair whose value > 0.8<jupyter_code>df.where(df>0.8).stack().index.tolist()<jupyter_output><empty_output><jupyter_text>let's digest1. step1: df > 0.8 will return a boolean dataframe2. step2: df.where without addtional argument will alter entries that is False as NaN (most important step)3. step3: NaN will be automatically igonored when calling stack() to construct multiIndex4. step4: extract multiIndex and chagne to list<jupyter_code># step1
df > 0.8
# step2
df.where(df>0.8)
# step3
df.where(df>0.8).stack()
# step4
df.where(df>0.8).stack().index<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1304791029561672, 'fraction_numerical': 0.03058103975535168, 'mean_word_length': 5.061728395061729, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '655605', 'license': 'MIT', 'n_tokens_mistral': 354, 'n_tokens_neox': 345, 'n_words': 93, 'path': 'pandas/examples/17_index_column_pair.ipynb', 'repo_name': 'CySecWee/ML', 'size': '981'}