I have a DataFrame with four columns. I want to convert this DataFrame to a python dictionary. I want the elements of first column be keys
and the elements of o
should a dictionary like:
{'red': '0.500', 'yellow': '0.250, 'blue': '0.125'}
be required out of a dataframe like:
a b
0 red 0.500
1 yellow 0.250
2 blue 0.125
simplest way would be to do:
dict(df.values.tolist())
working snippet below:
import pandas as pd
df = pd.DataFrame({'a': ['red', 'yellow', 'blue'], 'b': [0.5, 0.25, 0.125]})
dict(df.values.tolist())