2zadanie/tqdm.ipynb

132 lines
4.5 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"id": "bd70558d-d516-46a7-956d-d85685f46b96",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Простой процесс:\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Базовая загрузка: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 100/100 [00:01<00:00, 93.30it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Обработка строк таблицы:\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Анализ данных: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 6/6 [00:01<00:00, 3.32it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Стилизованная загрузка:\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Сохранение отчета: 100%|████████████████████| 100/100 [00:02<00:00, 48.43it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Все процессы завершены успешно!\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n"
]
}
],
"source": [
"from tqdm import tqdm\n",
"import time\n",
"import pandas as pd\n",
"\n",
"# 0. Создаем данные (чтобы не было ошибки \"df is not defined\")\n",
"data = {\n",
" \"Имя\": [\"Анна\", \"Борис\", \"Виктор\", \"Галина\", \"Дмитрий\", \"Елена\"],\n",
" \"Возраст\": [21, 22, 23, 24, 25, 26],\n",
" \"Баллы\": [89, 76, 95, 82, 90, 88]\n",
"}\n",
"df = pd.DataFrame(data)\n",
"\n",
"# 1. Базовый прогресс-бар\n",
"print(\"Простой процесс:\")\n",
"for i in tqdm(range(100), desc='Базовая загрузка'):\n",
" time.sleep(0.01)\n",
"\n",
"# 2. Использование tqdm для обработки данных таблицы\n",
"print(\"\\nОбработка строк таблицы:\")\n",
"# Здесь добавили .shape[0], чтобы tqdm знал общее количество строк\n",
"for index, row in tqdm(df.iterrows(), total=df.shape[0], desc='Анализ данных'):\n",
" time.sleep(0.3) # Симулируем обработку каждой строки\n",
"\n",
"# 3. Кастомная стилизация\n",
"print(\"\\nСтилизованная загрузка:\")\n",
"for i in tqdm(range(100), desc='Сохранение отчета', bar_format='{l_bar}{bar:20}{r_bar}'):\n",
" time.sleep(0.02)\n",
"\n",
"print(\"\\nВсе процессы завершены успешно!\")\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1beae766-f7ad-4e74-b6fa-a44ca8672667",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.13.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}