вести учет в переменной при чтении данных из read_sql_query с использованием chunksize - PullRequest
0 голосов
/ 25 сентября 2019
import pandas as pd
dbcon = ... # whatever

with open("out.csv", "w") as fh:

    chunks = pd.read_sql_query("SELECT * FROM table_name", dbcon,chunksize=10000)
    next(chunks).to_csv(fh, index=False)  # write the first chunk with the column names,
                                          # but ignore the index (which will be screwed up anyway due to the chunking)
    for chunk in chunks:
        chunk.to_csv(fh, index=False, header=False) # skip the column names from now on

в приведенном выше коде, как я могу получить количество строк в переменной, которые записываются в CSV-файл?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...