Python 如何将dataframe转换为SQL

Python 如何将dataframe转换为SQL,python,sql,pandas,Python,Sql,Pandas,要将数据帧转换为sql。我还想用我的sql表在桌面上获取.sql 这是我的代码: import pandas as pd from sqlalchemy import create_engine df = pd.DataFrame({'second':[5,6,7,8,9], 'first':['ne', 'da', 'ne', 'da', 'da'], 'third':[213,151,16,641,64]}) p

要将数据帧转换为sql。我还想用我的sql表在桌面上获取
.sql

这是我的代码:

import pandas as pd
from sqlalchemy import create_engine

df = pd.DataFrame({'second':[5,6,7,8,9],
                   'first':['ne', 'da', 'ne', 'da', 'da'],
                   'third':[213,151,16,641,64]})

print(df)

engine = create_engine('sqlite://', echo=False)

sample_sql_database = df.to_sql('sample_database', con=engine)
sample_sql_database = engine.execute("SELECT * FROM sample_database").fetchall()

print(sample_sql_database)

我正在使用
访问sql
,我的代码没有显示任何错误,但我不知道如何让我的表显示在桌面上,因为您没有提到正确的db\u uri,所以您无法在桌面上看到它。请在基本语法后至少提及名称:

create_engine('sqlite://** mention name here **', echo=False)
这对我有用,试试看:

import pandas as pd
from sqlalchemy import create_engine

df = pd.DataFrame({'second':[5,6,7,8,9],
                   'first':['ne', 'da', 'ne', 'da', 'da'],
                   'third':[213,151,16,641,64]})
print(df)

db_uri = 'sqlite:///file.db'
engine = create_engine(db_uri, echo=False)

sample_sql_database = df.to_sql('sample_database', con=engine)

sample_sql_database = engine.execute("SELECT * FROM sample_database").fetchall()

print(sample_sql_database)

您无法在桌面上看到它,因为您没有提到正确的db_uri。请在基本语法后至少提及名称:

create_engine('sqlite://** mention name here **', echo=False)
这对我有用,试试看:

import pandas as pd
from sqlalchemy import create_engine

df = pd.DataFrame({'second':[5,6,7,8,9],
                   'first':['ne', 'da', 'ne', 'da', 'da'],
                   'third':[213,151,16,641,64]})
print(df)

db_uri = 'sqlite:///file.db'
engine = create_engine(db_uri, echo=False)

sample_sql_database = df.to_sql('sample_database', con=engine)

sample_sql_database = engine.execute("SELECT * FROM sample_database").fetchall()

print(sample_sql_database)

您的表将导出到名为“sample_database”的数据库中。您必须查询数据库才能查看结果。您不能“在桌面上打开”。下载以查询数据库。表将导出到名为“sample_database”的数据库中。您必须查询数据库才能查看结果。您不能“在桌面上打开”。下载以查询您的db。它可以工作,我在deskop上获得了db.sqlite文件,但当我在deskop上打开它时,它的所有空值,如何查看来自datagrame的值它可以工作,我在deskop上获得了db.sqlite文件,但当我在deskop上打开它时,它的所有空值,如何查看来自datagrame的值