Last active
April 8, 2019 14:35
-
-
Save savfischer/fd133d2e969e75d10d2254b09a450185 to your computer and use it in GitHub Desktop.
Deutsche Industrie REIT-AG
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "csv" | |
arr_of_arrs = CSV.read('reit_properties.csv', encoding: 'iso-8859-1') | |
def fix_weird_characters(text) | |
text = text.encode!('utf-8') | |
text.gsub("ü", "ü") | |
end | |
CSV.open("organized_reit_properties.csv", "wb") do |csv| | |
csv << ["Address", "Type", "Tenant Use", "Rentable Area", "Property Area", | |
"In-Place rent (annualised)", "IPR/sqm.", "WALT", "Vacancy", "Fair value", "Yield"] | |
new_row = [] | |
arr_of_arrs.each_with_index do |row, row_index| | |
row.each_with_index do |cell, cell_index| | |
case cell | |
when 'Address' | |
address = fix_weird_characters row[cell_index + 1] | |
new_row.push address | |
when 'Type' | |
type = fix_weird_characters row[cell_index + 1] | |
new_row.push type | |
when 'Sector(s)', 'Branches' | |
sectors = fix_weird_characters row[cell_index + 1] | |
new_row.push sectors | |
end | |
end | |
if arr_of_arrs[-1] == row || arr_of_arrs[row_index - 1][0] == 'Address' | |
csv << new_row | |
new_row = [] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment