0

I have the following data frame:

      Factors    low   high
0      amount    2.5      4
1  grind_size      8     10
2   brew_time    3.5    4.5
3  grind_type   burr  blade
4       beans  light   dark

and I want to make following dict:

lows = { 'amount' : 2.5,
         'grind_size' : 8,
         'brew_time': 3.5,
         'grind_type': 'burr',
         'beans': 'light' }

How can I achieve that?

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
StupidBoy
  • 26
  • 2
  • 2
    Does this answer your question? [Convert a Pandas DataFrame to a dictionary](https://stackoverflow.com/questions/26716616/convert-a-pandas-dataframe-to-a-dictionary) – AlexisG Mar 25 '21 at 08:17

1 Answers1

1

You can get this dict with

dict(zip(df['Factors'], df['low']))

or

df.set_index('Factors')['low'].to_dict()
timgeb
  • 76,762
  • 20
  • 123
  • 145