-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostgresql
More file actions
22 lines (16 loc) · 751 Bytes
/
Copy pathpostgresql
File metadata and controls
22 lines (16 loc) · 751 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import os
import pandas as pd
from sqlalchemy import create_engine
# Conexão com o Postgres (ajuste se necessário)
engine = create_engine("postgresql+psycopg2://sales_user:sales_pass@localhost/sales_db")
# Caminho para os CSVs
data_folder = 'data'
# Para cada CSV, criar uma tabela com o nome do arquivo (sem .csv)
for file_name in os.listdir(data_folder):
if file_name.endswith('.csv'):
table_name = file_name.replace('.csv', '').lower()
file_path = os.path.join(data_folder, file_name)
print(f"Carregando {file_name} na tabela {table_name}...")
df = pd.read_csv(file_path)
df.to_sql(table_name, engine, if_exists='replace', index=False)
print("✅ Todos os arquivos foram carregados com sucesso!")