columns to dictionary pandas
pd.Series(df.A.values,index=df.B).to_dict()
columns to dictionary pandas
pd.Series(df.A.values,index=df.B).to_dict()
convert a dictionary into dataframe python
import pandas as pd
data = {'col_1': [3, 2, 1, 0], 'col_2': ['a', 'b', 'c', 'd']}
pd.DataFrame.from_dict(data, orient='index').T
dataframe to dictionary with one column as key
pd.Series(df.A.values,index=df.B).to_dict()
dataframe to dictionary
>>> df.to_dict('records')
[{'col1': 1, 'col2': 0.5}, {'col1': 2, 'col2': 0.75}]
convert pandas dataframe to dict with a column as key
df.set_index('columnName').T.to_dict()
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