Skip to content

Instantly share code, notes, and snippets.

@MikyPo
Created May 18, 2025 10:01
Show Gist options
  • Select an option

  • Save MikyPo/20de058f7835439e161f9b52c0780dde to your computer and use it in GitHub Desktop.

Select an option

Save MikyPo/20de058f7835439e161f9b52c0780dde to your computer and use it in GitHub Desktop.
view process bar
import pandas as pd
import numpy as np
from tqdm import tqdm
# 1. Генерация тестовой таблицы (1 000 000 строк)
def generate_test_data(rows=1000000):
data = {
'id': np.arange(1, rows+1),
'value': np.random.rand(rows) * 100,
'category': np.random.choice(['A', 'B', 'C', 'D'], size=rows)
}
return pd.DataFrame(data)
# 2. Функция обработки с прогресс-баром
def process_data(df):
# Включаем прогресс-бар для apply
tqdm.pandas(desc="Обработка строк")
# Вычисления
print('Возведение в квадрат')
df['squared'] = round(df['value'].progress_apply(lambda x: x**2), 2)
print()
print('Возведение в куб')
df['cubing '] = round(df['value'].progress_apply(lambda x: x**3), 2)
print()
print('Извлечение квадратного корня')
df['sqrt '] = round(df['value'].progress_apply(lambda x: np.sqrt(x)), 2)
return df
# Генерируем данные
df = generate_test_data()
# Обрабатываем с прогресс-баром
result = process_data(df)
print()
print('Итоговая таблица')
display(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment