[英]How do I create a progress bar when a DataFrame is initializing?
I want to get the number of rows each time a new one is created when I load a .csv
file into a dataframe : 我想在每次将
.csv
文件加载到数据帧时创建新行时获取行数:
def file_len(fname):
with open(fname) as f:
for i, l in enumerate(f):
pass
return i + 1
csv_path = "C:/...."
max_length = file_len(csv_path)
data = read_csv(csv_path, sep=';', encoding='utf-8')
With that code I get the max number of rows but I don't know how to get the number of rows in the dataframe, each time one is created. 使用该代码,我获得了最大行数,但我不知道如何在每次创建一行时获取数据帧中的行数。 I wanted to use them to make a 0-100% progress bar
我想用它们来制作0-100%的进度条
You can't do this - you would have to modify read_csv
function and maybe other functions in pandas. 你不能这样做 - 你必须修改
read_csv
函数和pandas中的其他函数。
EDIT: 编辑:
It seems it can bo done now with chunksize=rows_number
. 现在看来它可以用
chunksize=rows_number
。
Using only iterator=True
didn't work for me - or maybe it needed more rows. 仅使用
iterator=True
对我不起作用 - 或者可能需要更多行。
Try this 试试这个
import pandas as pd
from StringIO import StringIO
data = """A,B,C
foo,1,2,3
bar,4,5,6
baz,7,8,9
"""
reader = pd.read_csv(StringIO(data), chunksize=1)
for x in reader:
print x
print '--- next data ---'
result: 结果:
A B C
foo 1 2 3
--- next data ---
A B C
bar 4 5 6
--- next data ---
A B C
baz 7 8 9
--- next data ---
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.