首页 > 解决方案 > 移除 HBox 终端输出

问题描述

pandas我使用和将 excel 文件转换为 h5 文件tqdm

以下是我正在使用的代码的简化版本:

import pandas as pd
from tqdm.notebook import tqdm

# read raw table
pd.set_option('io.hdf.default.format', 'table')
store = pd.HDFStore('test.h5')

# get original file
original_file = ('test.xlsx')

# tables
table_names = ['A', 'B', 'C']

for name in tqdm(table_names):
    # some pre-process data
    df = pd.read_excel(original_file, sheet_name=name, skiprows=2)
    df.columns = [i.strip() for i in df.columns]
    df.index = pd.date_range('2020-01-01 00:00', periods=len(df.index),
                             freq='H', tz='UTC')
    del df['Date from']
    del df['Date to']

    df.index.name = 'date_time'

    # rename columns
    mapping = {...}
    if 'xxx' in name:
        df = df.rename(columns=mapping)

    # inject table to hdf store
    store[name] = df.copy()
    del df

store.close()

print('H5 file is ready')

上面的代码给了我一个奇怪的输出,如下所示:

HBox(children=(HTML(value=''), FloatProgress(value=0.0, max=9.0), HTML(value='')))

H5 file is ready

我猜这个HBox东西是一种显示 h5 文件创建过程的方式,就像加载栏一样。但是它没有显示任何内容并写下这一行...children=(HTML...。由于它没有给我任何信息,我想删除这一HBox行。但我不确定脚本中上面的哪个命令创建了这个。有任何想法吗?

顺便说一句,如果它很容易实现,工作进度条也可能很好。

标签: pythonpandasoutputtqdmhbox

解决方案


HBox相关tqdm.notebook。所以删除tqdm这个:

 for name in tqdm(table_names):

如果要显示进度,可以使用通常tqdm

from tqdm import tqdm  # not tqdm.notebook
for name in tqdm(table_names):

推荐阅读