我用pandas和tqdm将excel文件转换成h5文件。
下面是我使用的代码的精简版本:
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行。但是我不确定上面脚本中的哪个命令创建了这个。有什么想法吗?
顺便说一下,如果一个工作进度条很容易实现,那么它也是很好的。
发布于 2020-12-04 22:37:22
HBox与tqdm.notebook相关。因此,在下面的代码中删除tqdm:
for name in tqdm(table_names):如果想要显示进度,可以使用常用的tqdm
from tqdm import tqdm # not tqdm.notebook
for name in tqdm(table_names):https://stackoverflow.com/questions/65145492
复制相似问题