Answers for "how to take 2 columns from a dataframe and make a dictionary"

6

dictionary from two columns pandas

pd.Series(df.A.values,index=df.B).to_dict()
Posted by: Guest on September-25-2020
0

dict column to be in multiple columns python

In [2]: df = pd.DataFrame({'a':[1,2,3], 'b':[{'c':1}, {'d':3}, {'c':5, 'd':6}]})

In [3]: df
Out[3]:
   a                   b
0  1           {u'c': 1}
1  2           {u'd': 3}
2  3  {u'c': 5, u'd': 6}

In [4]: df['b'].apply(pd.Series)
Out[4]:
     c    d
0  1.0  NaN
1  NaN  3.0
2  5.0  6.0
Posted by: Guest on June-20-2020

Code answers related to "how to take 2 columns from a dataframe and make a dictionary"

Python Answers by Framework

Browse Popular Code Answers by Language