0

How can I convert the below dataframe to a dictionary where the key is values of 'node' and the value is values of 'label'?

   label   node
0   False   254
1   False   255
2   False   256
3   False   260
4   False   261
  • Maybe something like [this](https://stackoverflow.com/a/61614795/7867968)? – C.Nivs Sep 08 '21 at 19:57
  • This is already answered here: [convert a pandas dataframe to a dictionary](https://stackoverflow.com/questions/26716616/convert-a-pandas-dataframe-to-a-dictionary) – JunaidAfzal Sep 08 '21 at 20:05
  • It is already answered here: [convert a pandas dataframe to a dictionary](https://stackoverflow.com/questions/26716616/convert-a-pandas-dataframe-to-a-dictionary) – JunaidAfzal Sep 08 '21 at 20:08

1 Answers1

3

You can zip the two columns together:

>>> dict(zip(df["node"], df["label"]))
{254: False, 255: False, 256: False, 260: False, 261: False}
ddejohn
  • 8,775
  • 3
  • 17
  • 30