Skip to content

Instantly share code, notes, and snippets.

@Kristjan-Reinsberg
Last active June 18, 2025 13:36
Show Gist options
  • Select an option

  • Save Kristjan-Reinsberg/359a9d1e1bc0b0027e208e2807597b39 to your computer and use it in GitHub Desktop.

Select an option

Save Kristjan-Reinsberg/359a9d1e1bc0b0027e208e2807597b39 to your computer and use it in GitHub Desktop.
PYHON - CSV - KEEP
# https://colab.research.google.com/drive/1xpvf6F7pPlwmQIOR_-_F2rN7KyQa-Tsl#scrollTo=PRwadWWMFiXh
import csv
import json
input_file = 'export (1).csv'
output_file = 'filtered_services.json'
desired_columns = [
"IT teenuse nimi",
"Lühinimi",
"Lühikirjeldus",
"IT teenuse kategooria",
"Teenuse kategooria",
"Sihtgrupp",
"Juhendi asukoht"
]
filtered_rows = []
with open(input_file, mode='r', newline='', encoding='utf-8') as csvfile:
reader = csv.DictReader(csvfile, delimiter=';')
for idx, row in enumerate(reader, start=1):
if row.get("Staatus") == "KASUTUSES": #ONLY
filtered_row = {col: row.get(col, "") for col in desired_columns}
filtered_row['IT teenuse nimi'] = row.get("IT teenuse nimi").strip()
filtered_row['Sihtgrupp'] = row.get("Sihtgrupp").split('||')
filtered_row['Lühikirjeldus'] = row.get("Lühikirjeldus").replace("\n", "")
filtered_rows.append(filtered_row)
# Write the filtered data to a JSON file
with open(output_file, mode='w', encoding='utf-8') as jsonfile:
json.dump(filtered_rows, jsonfile, ensure_ascii=False, indent=4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment