Create dictionary from results of DataFrame in pandas

前端 未结 5 1540
旧时难觅i
旧时难觅i 2021-01-16 16:35

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

5条回答
  •  日久生厌
    2021-01-16 17:12

    Maybe not the best in terms of performance, but you could use iterrows:

    import numpy as np
    results = {}
    for i, row in df.iterrows():
        results[i] = list(df.columns[~np.isnan(row)])
    

提交回复
热议问题