我有一个哈希数组,如下所示。我想将一些字段的值与自定义分隔符合并。在这里,我只在阵列中显示两个哈希,它可能有更多。但是,它们总是与此处所示的顺序相同。
import tensorflow.contrib.learn as learn
classifier = learn.DNNClassifier(hidden_units=[10, 20, 10], n_classes=2)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-30-0273d6847e2b> in <module>()
----> 1 classifier = learn.DNNClassifier(hidden_units=[10, 20, 10], n_classes=2)
TypeError: __init__() missing 1 required positional argument: 'feature_columns'
我想修改详细信息。我想构建新的领域。
{
"details": [
{
"place": "abc",
"group": 3,
"year": 2006,
"id": 1304,
"street": "xyz 14",
"lf_number": "0118",
"code": 4433,
"name": "abc coorperation",
"group2": 3817,
"group1": 32,
"postal_code": "22926",
"status": 2
},
{
"place": "cbc",
"group": 2,
"year": 2007,
"id": 4983,
"street": "mnc 14",
"lf_number": "0145",
"code": 4433,
"name": "abc coorperation",
"group2": 3817,
"group1": 32,
"postalcode": "22926",
"status": 2
}
],
"@timestamp": "2017-09-04",
"parent": {
"child": [
{
"w_2": 0.5,
"w_1": 0.1,
"id": 14226,
"name": "air"
},
{
"w_2": null,
"w_1": 91,
"id": 25002,
"name": "Water"
}]
},
"p_name": "anacin",
"@version": "1",
"id": 28841
}
如何为详细信息中的所有值实现此目的。以下是最终结果的样子。
Field 1) coorperations: (details.name | details.postal_code details.street ; details.name | details.postal_code details.street)
Output:
Coorperations: (abc coorperation |22926 xyz 14; abc coorperation | 22926 mnc 14)
Field 2) access_code: (details.status-details.id-details.group1-details.group2-details.group(always two digit)/details.year(only last two digits); details.status-details.id-details.group1-details.group2-details.group(always two digit)/details.year(only last two digits))
Output: access_code (2-32-3817-03-06; 2-32-3817-02-07)
答案 0 :(得分:0)
您可以尝试在rails控制台中运行此代码,哈希是您的json:
new_hash = hash.except(:details)
coorperations = ""
access_code = ""
elements = hash[:details]
elements.each do |element|
coorperations = "#{coorperations}#{if coorperations.present? then '; ' else '' end}#{element[:name]} | #{element[:postal_code]} #{element[:street]}"
access_code = "#{access_code}#{if access_code.present? then '; ' else '' end}#{element[:status]}-#{element[:id]}-#{element[:group1]}-#{element[:group2]}-#{element[:group1]}-#{element[:group]}"
end
new_hash.merge!(Coorperations: coorperations)
new_hash.merge!(access_code: access_code)
new_hash