-
-
Save Uvacoder/945db8cdf3bf2e582250b7b2a090cc26 to your computer and use it in GitHub Desktop.
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
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
| 1000001-x 86 56 64 95 | |
| 1000002-y 81 67 63 53 | |
| 1000003-x 45 46 97 67 | |
| 1000004-x 75 68 95 72 | |
| 1000005-y 89 54 72 66 | |
| 1000006-z 66 70 84 90 | |
| 1000007-x 68 76 84 89 | |
| 1000008-z 97 62 56 53 | |
| 1000009-y 76 48 90 51 | |
| 1000010-y 62 67 92 70 | |
| 1000011-z 92 53 75 76 | |
| 1000012-z 45 91 63 45 |
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
| from prettytable import PrettyTable | |
| def baca(namafile): | |
| with open(namafile) as file_object: | |
| arr_dat = [[],[],[],[]] | |
| result = {"clo1" : [],"clo2" : [],"clo3" : [],"clo4" : []} | |
| for line in file_object: | |
| line = line.replace("\n", "").split("\t")[1:] | |
| line = [int(x) for x in line] | |
| for num in range(4): | |
| arr_dat[num].append(line[num]) | |
| # masukan hasil ke dict | |
| for i in range(len(arr_dat)): | |
| result[f"clo{i+1}"].append(round(sum(arr_dat[i]) / len(arr_dat[i]),1)) | |
| result[f"clo{i+1}"].append(max(arr_dat[i])) | |
| result[f"clo{i+1}"].append(min(arr_dat[i])) | |
| result[f"clo{i+1}"].append(len([x for x in arr_dat[i] if x <= 50 ])) | |
| print(f"isi dict sebelum diolah menjadi tabel : {result}") | |
| return result | |
| def tampilkan_semua(namafile): | |
| p = PrettyTable() | |
| p.field_names = ["Nomor Induk", "CLO 1", "CLO 2", "CLO 3", "CLO 4"] | |
| with open("data.csv") as file_object: | |
| for line in file_object: | |
| p.add_row(line.replace("\n", "").split("\t")) | |
| print(p) | |
| def tampilkan_report(): | |
| p = PrettyTable() | |
| p.field_names = ["Nama CLO", "Rata-Rata", "Tertinggi", "Terendah", "Dibawah Standar"] | |
| acuan = baca('data.csv') | |
| for i in range(4): | |
| p.add_row([f"CLO {i+1}", acuan[f"clo{i+1}"][0], acuan[f"clo{i+1}"][1], acuan[f"clo{i+1}"][2], acuan[f"clo{i+1}"][3]]) | |
| print(p) | |
| # tampilkan data clo dari file data.csv | |
| tampilkan_semua('data.csv') | |
| # buat laporan | |
| tampilkan_report() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment