【发布时间】:2019-02-28 10:25:10
【问题描述】:
我有这个字符串:
Model: ARIMA BIC: 417.2273
Dependent Variable: D.Sales of shampoo over a three year period Log-Likelihood: -196.17
Date: 2018-09-24 13:20 Scale: 1.0000
No. Observations: 35 Method: css-mle
Df Model: 6 Sample: 02-01-1901
Df Residuals: 29 12-01-1903
Converged: 1.0000 S.D. of innovations: 64.241
No. Iterations: 19.0000 HQIC: 410.098
AIC: 406.3399
我想把它编成字典。我已经使用了: split("\n") 我得到了
Model: ARIMA BIC: 417.2273
Dependent Variable: D.Sales of shampoo over a three year period Log-Likelihood: -196.17
Date: 2018-09-24 13:20 Scale: 1.0000
No. Observations: 35 Method: css-mle
Df Model: 6 Sample: 02-01-1901
Df Residuals: 29 12-01-1903
Converged: 1.0000 S.D. of innovations: 64.241
No. Iterations: 19.0000 HQIC: 410.098
AIC: 406.3399
但我没有看到将其放入字典的好方法。也许我遗漏了一些明显的东西?
另外,请注意“示例:”旁边的日期格式
我想要类似:{"Model": "ARIMA", "BIC": 417.2273, ...}
【问题讨论】:
-
你还没有显示结果字典应该是什么样子
-
您有关于如何导入字符串的选项吗?您可以查看解析固定宽度文件的示例here,这似乎是。
-
不,我不这么认为。归根结底,这是一个字符串解析问题。
-
第一行是否总是包含 Model 和 BIC 密钥?
-
您有所有可能的键的列表吗? (模型,Bic..)? ':' 字符可以出现在 values 中吗?
标签: python string python-3.x split