【发布时间】:2017-06-13 05:52:31
【问题描述】:
我有数据框 best_scores 包含
subsample colsample_bytree learning_rate max_depth min_child_weight \
3321 0.8 0.8 0.3 2 3
objective scale_pos_weight silent
3321 binary:logistic 1.846154 1
我想把它转换成字典params,比如:
params
{'colsample_bytree': 0.8,
'learning_rate': 0.3,
'max_depth': 2,
'min_child_weight': 3,
'objective': 'binary:logistic',
'scale_pos_weight': 1.8461538461538463,
'silent': 1,
'subsample': 0.8}
但是如果我跑了
best_scores.to_dict(orient='records')
我明白了:
[{'colsample_bytree': 0.8,
'learning_rate': 0.3,
'max_depth': 2,
'min_child_weight': 3,
'objective': 'binary:logistic',
'scale_pos_weight': 1.8461538461538463,
'silent': 1L,
'subsample': 0.8}]
你能帮忙吗?
【问题讨论】:
-
你不行吗
best_scores.to_dict(orient='records')[0] -
@Jean-FrançoisFabre 谢谢!任何线索为什么沉默是 L 而不是 int?
-
可能是因为它是用 long int 初始化的。您必须使用 python 2。您可以转换回 int。别担心,它工作正常(只是占用更多内存而已)
标签: python pandas dictionary dataframe