36 lines
839 B
Python
36 lines
839 B
Python
import pandas as pd
|
|
import glob
|
|
import re
|
|
import os
|
|
|
|
percorso = "main/datasets/slices/*.xlsx"
|
|
files = glob.glob(percorso)
|
|
|
|
def chiave_ordinamento(file):
|
|
nome = os.path.basename(file)
|
|
|
|
# Caso speciale
|
|
if "first2000_reviewed" in nome:
|
|
return 0
|
|
|
|
# Estrae il primo numero del range (es: 2000 da 2000_2500)
|
|
match = re.search(r'(\d+)_', nome)
|
|
if match:
|
|
return int(match.group(1))
|
|
|
|
# fallback (nel dubbio lo manda in fondo)
|
|
return float('inf')
|
|
|
|
files_ordinati = sorted(files, key=chiave_ordinamento)
|
|
|
|
# Debug: stampa ordine
|
|
print("Ordine file:")
|
|
for f in files_ordinati:
|
|
print(os.path.basename(f))
|
|
|
|
# Concatenazione
|
|
df_unito = pd.concat((pd.read_excel(f) for f in files_ordinati), ignore_index=True)
|
|
|
|
df_unito.to_excel("final_dataset.xlsx", index=False)
|
|
|
|
print("Unione completata!") |