<jupyter_start><jupyter_text>Połączenie z bazą danych przy pomocy sqlAlchemy<jupyter_code>from sqlalchemy import create_engine

db_string = "postgres://postgres:postgres@localhost:5432/test"

db = create_engine(db_string)
connection_sqlalchemy = db.connect()<jupyter_output><empty_output><jupyter_text>Zapytanie do bazy i wypisanie wyników<jupyter_code>result_set = db.execute("SELECT * FROM city")  
for r in result_set:  
    print(r)<jupyter_output><empty_output><jupyter_text>Połączenie z bazą danych przy pomocy psycopg2 i pandas<jupyter_code>import psycopg2 as pg
import pandas as pd

connection = pg.connect(host='localhost', port=5432, dbname='test', user='postgres', password='<PASSWORD>')<jupyter_output><empty_output><jupyter_text>Zapytanie do bazy i wypisanie wyników<jupyter_code>df = pd.read_sql('select * from city',con=connection)
df<jupyter_output><empty_output><jupyter_text>Połączenie za pomocą sqlAlchemy i pandas<jupyter_code>df = pd.read_sql('select * from city', con=connection_sqlalchemy)
df<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10526315789473684, 'fraction_numerical': 0.009569377990430622, 'mean_word_length': 9.673469387755102, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '550925', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 407, 'n_tokens_neox': 403, 'n_words': 69, 'path': 'Analiza i Bazy Danych 2021/Lab 3/example.ipynb', 'repo_name': 'piotrbullet/public_lectures', 'size': '1043'}