neznayhz/tqdm.ipynb
2026-04-29 22:47:04 +03:00

145 lines
4.1 KiB
Plaintext
Raw 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": 1,
"id": "1b768852-5883-4ca4-86e7-d4a93c9a1a55",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Таблица создана:\n",
" ID Data\n",
"0 0 -1.082938\n",
"1 1 -0.374716\n",
"2 2 0.609893\n",
"3 3 0.032177\n",
"4 4 1.138623\n",
"\n",
"Запускаю цикл с прогресс-баром...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Загрузка: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████| 50/50 [00:02<00:00, 19.56it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Первый цикл готов!\n",
"\n",
"Обрабатываю строки таблицы...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Обработка: 100it [00:00, 20892.13it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Обработано строк: 100\n",
"\n",
"Запускаю второй прогресс-бар...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Вычисления: 100%|\u001b[34m████████████████████████████████████████████████████████████████████████████████████████████████████████\u001b[0m| 20/20 [00:02<00:00, 9.86it/s]\u001b[0m"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Все вычисления завершены!\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n"
]
}
],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"from tqdm import tqdm\n",
"import time\n",
"\n",
"df = pd.DataFrame({\n",
" 'ID': range(100),\n",
" 'Data': np.random.randn(100)\n",
"})\n",
"\n",
"print(\"Таблица создана:\")\n",
"print(df.head())\n",
"\n",
"print(\"\\nЗапускаю цикл с прогресс-баром...\")\n",
"for i in tqdm(range(50), desc='Загрузка'):\n",
" time.sleep(0.05)\n",
"\n",
"print(\"Первый цикл готов!\")\n",
"\n",
"print(\"\\nОбрабатываю строки таблицы...\")\n",
"schetchik = 0\n",
"for index, row in tqdm(df.iterrows(), desc=\"Обработка\"):\n",
" vremya = row['Data'] ** 2\n",
" schetchik = schetchik + 1\n",
"\n",
"print(f\"Обработано строк: {schetchik}\")\n",
"\n",
"print(\"\\nЗапускаю второй прогресс-бар...\")\n",
"for i in tqdm(range(20), desc='Вычисления', colour='blue'):\n",
" result = i * 2\n",
" time.sleep(0.1)\n",
"\n",
"print(\"Все вычисления завершены!\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fe6502c6-7248-4a62-9d1c-38fd51c85549",
"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
}