Answers for "convert pandas 2 columns to 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

create dict from two columns pandas

In [6]: df = pd.DataFrame(randint(0,10,10000).reshape(5000,2),columns=list('AB'))

In [7]: %timeit dict(zip(df.A,df.B))
1000 loops, best of 3: 1.27 ms per loop

In [8]: %timeit pd.Series(df.A.values,index=df.B).to_dict()
1000 loops, best of 3: 987 us per loop
Posted by: Guest on September-08-2020

Code answers related to "convert pandas 2 columns to dictionary"

Python Answers by Framework

Browse Popular Code Answers by Language