我正在尝试使用Pandas读取一个没有任何标题的非结构化CSV文件。不同行的列数不同,列数没有明确的上限。现在是10,但可能会增加到15。
CSV文件内容示例:
a;b;c
a;b;c;d;e;;;f
a;;
a;b;c;d;e;f;g;h;;i
a;b;
....
下面是我如何使用Python Pandas读取它的:
pd.DataFrame(pd.read_csv(path, sep=";", header=None, usecols=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
names=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'],
nrows=num_of_rows + 1))
但是这会产生FutureWarning: Defining usecols with out of bounds indices is deprecated and will raise a ParserError in a future version.
警告消息,我不希望我的代码因为这个原因而停止工作。
我的问题是,有没有一种方法可以使用Pandas(或任何其他等效的快速库)以未来安全的方式读取这样一个非结构化的CSV文件?
1条答案
按热度按时间oiopk7p51#
您可以用途:
更新
其他可能性: