我已經下載使用CSV文件HTTParty並在本地保存的文件,所以我可以在以後的日子檢查它,但它看來,如果數據格式不正確格式化CSV文件格式正確
[["Team Name", "User Name", "Dataset Name", "No of Searches", "Credits Remaining"], ["", "",
"DRI", "129", "99085"], ["", "", "Property Register Search (G)", "124", "99414"], ["", "",
"Landline Verification", "1", "99783"], ["", "",
"Equifax (G)", "372", "97798"], ["", "", "Director Register", "135", "98499"], ["", "",
"Mobile Verification", "2", "99845"], ["", "",
"BT OSIS", "428", "91588"], ["", "",
"Experian (G)", "97", "99913"], ["", "", "Standard (G)",
"873", "82151"], ["", "", "CCJ", "120", "98367"]]
這樣我就可以使用紅寶石提供的CSV
類,我需要的數據是以下列格式嗎?
Team Name, User Name, Dataset Name, No of Searches, Credits Remaining
"", "", DRI, 129, 99085
"", "", Property Register Search (G), 124, 99414]
"", "", Landline Verification, 1, 99783
"", "", Equifax (G), 372, 97798
"", "", Director Register, 135, 98499
"", "", Mobile Verification, 2, 99845
"", "", BT OSIS, 428, 91588]
"", "", Experian (G), 97, 99913
"", "", Standard (G), 873, 82151
"", "", CCJ, 120, 98367
什麼,我希望做到的,是得到一個地步,我可以湊了這一點,所以我可以爲Dataset Name
Standard
希望訪問Credits Remaining
有道理
感謝
UPDATE
感謝@mudasobwa爲您的答案,我現在有我的csv文件內容在一個哈希值的N排列的(我認爲:))
{"TeamName"=>[nil, nil, nil, nil, nil, nil, nil, nil, nil, nil],
"UserName"=>[nil, nil, nil, nil, nil, nil, nil, nil, nil, nil],
"DatasetName"=> ["DRI", "PropertyRegisterSearch(G)", "LandlineVerification","Equifax(G)", "DirectorRegister", "MobileVerification", "BTOSIS", "Experian(G)", "Standard(G)","CCJ"],
"NoofSearches"=>["129", "124", "1", "372", "135", "2", "428", "97", "873", "120"],
"CreditsRemaining"=>["99085", "99414", "99783", "97798", "98499", "99845", "91588", "99913", "82151", "98367"]
}
我該如何獲得NoofSearches
是DatasetName
DRI
對應的,所以我希望得到129
返回
我不確定ruby需要什麼,但是您可以輕鬆將第一個轉換爲第二個。編寫一個快速程序刪除所有'['括號,並用換行符替換']'。 –
這是第一個代碼示例,您下載的CSV或使用Ruby生成的東西? –
因此,數據似乎與我一致,重新格式化您的數組顯示此: –