[英]Use TQDM Progress Bar with Pandas
使用 Pandas 导入和索引大型数据集时是否可以使用 TQDM 进度条?
这是我正在导入、索引和使用 to_datetime 的一些 5 分钟数据的示例。 这需要一段时间,如果能看到进度条就好了。
#Import csv files into a Pandas dataframes and convert to Pandas datetime and set to index
eurusd_ask = pd.read_csv('EURUSD_Candlestick_5_m_ASK_01.01.2012-05.08.2017.csv')
eurusd_ask.index = pd.to_datetime(eurusd_ask.pop('Gmt time'))
通过形状求长度
for index, row in tqdm(df.iterrows(), total=df.shape[0]):
print("index",index)
print("row",row)
with tqdm(total=Df.shape[0]) as pbar:
for index, row in Df.iterrows():
pbar.update(1)
...
tqdm > 4.24 有一个解决方法。 根据https://github.com/tqdm/tqdm#pandas-integration :
from tqdm import tqdm
# Register `pandas.progress_apply` and `pandas.Series.map_apply` with `tqdm`
# (can use `tqdm_gui`, `tqdm_notebook`, optional kwargs, etc.)
tqdm.pandas(desc="my bar!")
eurusd_ask['t_stamp'] = eurusd_ask['Gmt time'].progress_apply(lambda x: pd.Timestamp)
eurusd_ask.set_index(['t_stamp'], inplace=True)
您可以通过正常读取文件逐行填充 Pandas 数据帧,然后简单地将每个新行作为新行添加到数据帧中,尽管这比仅使用 Pandas 自己的读取方法要慢一些。
我发现它很容易实现。 您只需要添加 total 参数。
import pandas as pd
df = pd.read_excel(PATH_TO_FILE)
for index, row in tqdm(df.iterrows(), total=df.shape[0], desc=f'Reading DF'):
print(row(['df_colum'])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.