Pandas read_csv shape[0] 或 len(index) 函数返回我计算机上的 2000 万行文件的 19929388 行。但是下面的 powershell 命令返回 2000 万。我的代码有问题吗?
Powershell - 返回 20000000
[int]$LinesInFile = 0
$reader = New-Object IO.StreamReader 'File.csv'
while($reader.ReadLine() -ne $null){ $LinesInFile++ }
Python - 返回 19929388
df = pd.read_csv(path, low_memory=(False), delimiter='|', header=None)
index = df.shape[0]
print(index)
答案 0 :(得分:0)
想通了。 Pandas 由于未关闭的双引号而跳过了一些行,即使我没有为我的文件声明限定符。
只需在 pd.read_csv() 上添加 quoting=csv.QUOTE_NONE 即可解决。
这篇文章帮助了我link