Spaces:
Sleeping
Sleeping
Create clean_csv.py
Browse files- clean_csv.py +18 -0
clean_csv.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import csv
|
2 |
+
|
3 |
+
# Nama file input dan output
|
4 |
+
input_file = "dataset.csv"
|
5 |
+
output_file = "cleaned_dataset.csv"
|
6 |
+
|
7 |
+
# Bersihkan dataset
|
8 |
+
with open(input_file, "r") as infile, open(output_file, "w", newline="") as outfile:
|
9 |
+
reader = csv.reader(infile)
|
10 |
+
writer = csv.writer(outfile)
|
11 |
+
|
12 |
+
# Periksa setiap baris
|
13 |
+
for row in reader:
|
14 |
+
# Hanya simpan baris dengan 2 kolom
|
15 |
+
if len(row) == 2:
|
16 |
+
writer.writerow(row)
|
17 |
+
|
18 |
+
print(f"Dataset telah dibersihkan. Simpan ke: {output_file}")
|