dataframe to dictionary
>>> df.to_dict('records')
[{'col1': 1, 'col2': 0.5}, {'col1': 2, 'col2': 0.75}]
dataframe to dictionary
>>> df.to_dict('records')
[{'col1': 1, 'col2': 0.5}, {'col1': 2, 'col2': 0.75}]
pandas row from dict
data = {'row_1': [3, 2, 1, 0], 'row_2': ['a', 'b', 'c', 'd']}
pd.DataFrame.from_dict(data, orient='index')
pandas dict from row
import pandas as pd
# your df
# =========================
print(df)
id score1 score2 score3 score4 score5
0 1 0.0000 0.1087 0.0000 0.0786 1
1 2 0.0532 0.3083 0.2864 0.4464 1
2 3 0.0000 0.0840 0.8090 0.2331 1
# to_dict
# =========================
df.to_dict(orient='records')
Out[318]:
[{'id': 1.0,
'score1': 0.0,
'score2': 0.10865899999999999,
'score3': 0.0,
'score4': 0.078597,
'score5': 1.0},
{'id': 2.0,
'score1': 0.053238000000000001,
'score2': 0.308253,
'score3': 0.28635300000000002,
'score4': 0.44643299999999997,
'score5': 1.0},
{'id': 3.0,
'score1': 0.0,
'score2': 0.083978999999999998,
'score3': 0.80898300000000001,
'score4': 0.23305200000000001,
'score5': 1.0}]
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