DEV Community

Cover image for 🐍Como Importar Dados do Excel para SQLite com Python em Poucas Linhas
Alexandre Justen Filho
Alexandre Justen Filho

Posted on

🐍Como Importar Dados do Excel para SQLite com Python em Poucas Linhas

Neste post, vou ensinar como transferir dados de uma planilha Excel diretamente para um banco de dados SQLite usando apenas algumas linhas de código em Python. Muito útil para quem precisa centralizar dados em um banco de dados, especialmente para uso em aplicações que fazem consultas frequentes, como dashboards ou ferramentas de análise!

  1. Bibliotecas:
import pandas as pd
import sqlite3

Enter fullscreen mode Exit fullscreen mode
  1. Carregar o Arquivo Excel:
arquivo_excel = './teste.xlsx'
df = pd.read_excel(arquivo_excel)

Enter fullscreen mode Exit fullscreen mode
  1. Conectar ao Banco de Dados SQLite:
conexao = sqlite3.connect('database.db')

Enter fullscreen mode Exit fullscreen mode
  1. Exportar os Dados para o SQLite:
df.to_sql('tabela_excel', conexao, if_exists='replace', index=False)

Enter fullscreen mode Exit fullscreen mode
  1. Fechar a Conexão e Confirmação:
conexao.close()
print("Dados importados com sucesso!")

Enter fullscreen mode Exit fullscreen mode

Dessa forma em poucas linhas de código temos a nossa tabela xlsx exportada para um banco SQLite!

Image description

Image description

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay