Initial commit
This commit is contained in:
36
Preprocess2.py
Normal file
36
Preprocess2.py
Normal file
@ -0,0 +1,36 @@
|
||||
import pandas as pd
|
||||
import glob
|
||||
import os
|
||||
|
||||
# Path ke folder yang berisi file Excel
|
||||
folder_path = "MyData/Final" # Ganti dengan path folder kamu
|
||||
|
||||
# Cari semua file Excel dalam folder
|
||||
files = glob.glob(f"{folder_path}/*.xlsx")
|
||||
|
||||
# Tentukan nama kolom yang diinginkan
|
||||
columns = ['410nm', '435nm', '460nm', '485nm',
|
||||
'510nm', '535nm', '560nm', '585nm',
|
||||
'610nm', '645nm', '680nm', '705nm',
|
||||
'730nm', '760nm', '810nm', '860nm',
|
||||
'900nm', '940nm']
|
||||
|
||||
# List untuk menyimpan semua dataframe
|
||||
dataframes = []
|
||||
|
||||
# Loop untuk membaca setiap file Excel
|
||||
for file in files:
|
||||
df = pd.read_csv(file) # Membaca file Excel hanya dengan jumlah kolom yang sesuai
|
||||
df.columns = columns # Menetapkan nama kolom sesuai daftar
|
||||
filename = os.path.basename(file) # Mengambil nama file tanpa path
|
||||
df["Label_Temp"] = filename.split(".")[0] # Menambahkan kolom Label
|
||||
df['Label'] = df.apply(lambda x: x['Label_Temp'].split("_")[0], axis=1)
|
||||
dataframes.append(df) # Menyimpan ke dalam list
|
||||
|
||||
# Menggabungkan semua DataFrame
|
||||
df_final = pd.concat(dataframes, ignore_index=True)
|
||||
|
||||
# Simpan ke dalam file csv baru
|
||||
df_final.to_csv("MyData/Final/Coffe Brewing Level - Spectroscopy.csv", index=False)
|
||||
|
||||
print("File berhasil disimpan sebagai output.xlsx")
|
Reference in New Issue
Block a user