Last active
June 18, 2025 13:36
-
-
Save Kristjan-Reinsberg/359a9d1e1bc0b0027e208e2807597b39 to your computer and use it in GitHub Desktop.
PYHON - CSV - KEEP
This file contains hidden or 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
| # 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