DATACAMP

作者: 山猪打不过家猪 | 来源:发表于2023-01-27 06:20 被阅读0次

1.ETL

  • sqlalchemy to pandas
import sqlalchemy 
# Function to extract table to a pandas DataFrame
def extract_table_to_pandas(tablename, db_engine):
    query = "SELECT * FROM {}".format(tablename)
    return pd.read_sql(query, db_engine)

# Connect to the database using the connection URI
connection_uri = "postgresql://repl:password@localhost:5432/pagila" 
db_engine = sqlalchemy.create_engine(connection_uri)

# Extract the film table into a pandas DataFrame
extract_table_to_pandas("film", db_engine)

# Extract the customer table into a pandas DataFrame
extract_table_to_pandas("customer", db_engine)

相关文章

网友评论

      本文标题:DATACAMP

      本文链接:https://www.haomeiwen.com/subject/gxtehdtx.html