dictionary from two columns pandas
pd.Series(df.A.values,index=df.B).to_dict()
dictionary from two columns pandas
pd.Series(df.A.values,index=df.B).to_dict()
dataframe to dictionary with one column as key
pd.Series(df.A.values,index=df.B).to_dict()
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
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us