I have a dataframe with results as below. Sample dataframe shown actual one is much larger. I want to get a dictionary (or another structure if it will be faster) with the
You can do boolean indexing on the dataframe columns in a dictionary comprehension.
>>> {idx: df.columns[row].tolist() for idx, row in df.notnull().iterrows()} {1: ['MSFT'], 2: ['GOOG', 'AMZN'], 3: ['AAPL', 'AMZN', 'FB'], 4: ['FB']}