Warning: mkdir(): No space left on device in /var/www/tgoop/post.php on line 37

Warning: file_put_contents(aCache/aDaily/post/sqlhub/--): Failed to open stream: No such file or directory in /var/www/tgoop/post.php on line 50
Data Science. SQL hub@sqlhub P.2130
SQLHUB Telegram 2130
This media is not supported in your browser
VIEW IN TELEGRAM
🖥 PYTHON: ХИТРЫЙ ТРЮК С SQL

Если вы работаете с большими таблицами в SQL через Python, и не хотите тянуть всё в память, используйте ленивую подгрузку данных с генерацией чанков. Это особенно полезно, если вы делаете агрегации, фильтрации или сохраняете результат в файл — можно обрабатывать данные частями, не загружая весь датасет сразу.

Удобно, быстро и экономит память. Работает даже с миллионами строк.


import pandas as pd
from sqlalchemy import create_engine

# подключение к базе данных (пример для PostgreSQL)
engine = create_engine("postgresql://user:password@localhost:5432/dbname")

# читаем по 10000 строк за раз
chunk_iter = pd.read_sql("SELECT * FROM big_table", engine, chunksize=10000)

# обработка: сохраняем отфильтрованные строки в файл
with open("filtered_output.csv", "w", encoding="utf-8") as f:
for i, chunk in enumerate(chunk_iter):
filtered = chunk[chunk["amount"] > 1000]
filtered.to_csv(f, index=False, header=(i == 0))


https://www.youtube.com/shorts/y5orXDD2mdU
Please open Telegram to view this post
VIEW IN TELEGRAM
17🔥4👍2



tgoop.com/sqlhub/2130
Create:
Last Update:

🖥 PYTHON: ХИТРЫЙ ТРЮК С SQL

Если вы работаете с большими таблицами в SQL через Python, и не хотите тянуть всё в память, используйте ленивую подгрузку данных с генерацией чанков. Это особенно полезно, если вы делаете агрегации, фильтрации или сохраняете результат в файл — можно обрабатывать данные частями, не загружая весь датасет сразу.

Удобно, быстро и экономит память. Работает даже с миллионами строк.


import pandas as pd
from sqlalchemy import create_engine

# подключение к базе данных (пример для PostgreSQL)
engine = create_engine("postgresql://user:password@localhost:5432/dbname")

# читаем по 10000 строк за раз
chunk_iter = pd.read_sql("SELECT * FROM big_table", engine, chunksize=10000)

# обработка: сохраняем отфильтрованные строки в файл
with open("filtered_output.csv", "w", encoding="utf-8") as f:
for i, chunk in enumerate(chunk_iter):
filtered = chunk[chunk["amount"] > 1000]
filtered.to_csv(f, index=False, header=(i == 0))


https://www.youtube.com/shorts/y5orXDD2mdU

BY Data Science. SQL hub


Share with your friend now:
tgoop.com/sqlhub/2130

View MORE
Open in Telegram


Telegram News

Date: |

You can invite up to 200 people from your contacts to join your channel as the next step. Select the users you want to add and click “Invite.” You can skip this step altogether. Concise The court said the defendant had also incited people to commit public nuisance, with messages calling on them to take part in rallies and demonstrations including at Hong Kong International Airport, to block roads and to paralyse the public transportation system. Various forms of protest promoted on the messaging platform included general strikes, lunchtime protests and silent sit-ins. To view your bio, click the Menu icon and select “View channel info.” With Bitcoin down 30% in the past week, some crypto traders have taken to Telegram to “voice” their feelings.
from us


Telegram Data Science. SQL hub
FROM American