python - 移除 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
行。但我不确定脚本中上面的哪个命令创建了这个。有任何想法吗?
顺便说一句,如果它很容易实现,工作进度条也可能很好。
解决方案
HBox
相关tqdm.notebook
。所以删除tqdm
这个:
for name in tqdm(table_names):
如果要显示进度,可以使用通常tqdm
:
from tqdm import tqdm # not tqdm.notebook
for name in tqdm(table_names):
推荐阅读
- python - Python Elasticsearch 错误排序关键字字段
- azure - 无法从 Azure 容器注册表中提取映像
- sql - 如何使用 GridControl 将变量发送到存储过程
- javascript - 从javascript中的字符串中去除逗号和非数字字符
- database - 在 MongoDB 中组织集合以存储交易数据的快速结构是什么?
- correlation - 有没有办法计算a和b之间二元变量的相关系数?
- scala - 让 State 如何与 Kleisli 合作?
- node.js - 如何将会话参数传递给猫鼬发布更新中间件?
- c - 当我尝试将文件读取到结构时,我的程序退出
- sql - SQL 只获取列中所有值的项目