我正在尝试使用python中的pandas来获取数据框的尺寸(形状),而不必首先在内存中读取整个数据框,因为文件很大。
为了以最小的文件加载到内存中来获取列数,例如,我可以使用下面的参数。
import pandas as pd
pd = pd.read_csv("myData.csv", nrows=1)
print(pd.shape)
To get the row numbers I can use the argument usecols = [1]
when reading the file but there must be a simpler way of doing this.
如果还有其他可以轻松为我提供此类元数据信息的软件包或脚本,我也将很高兴。我确实正在寻找元数据,例如列名,行数,列数等,但我不想读入整个文件!
You don't even need pandas for this. Use the built-in
csv
module to parse the file: