我想导入一个包含信息的CSV文件,它具有随机的空行,我想忽略这些行,只是跳过一下,例如,我有一个.txt文件,其中包含这样的信息:
Audi 90;200;Germany;22/10/19;150;
Bmw e46;350;Germany;22/10/19;100;
Mazda mx5;183;Japan;20/09/19;97;
Ford mustang;350;USA;21/04/19;278;
Lada;99999;Russia;20/11/19;99999;
我希望我的代码像这样输出它:
Audi 90;200;Germany;22/10/19;150;
Bmw e46;350;Germany;22/10/19;100;
Mazda mx5;183;Japan;20/09/19;97;
Ford mustang;350;USA;21/04/19;278;
Lada;99999;Russia;20/11/19;99999;
我用于打开和设置表格的代码如下:
import csv
from tabulate import tabulate as tb
def file_opening():
file = input("Enter .txt file name:")
open(file + '.txt', 'r')
fields = list(csv.reader(open(file + '.txt', 'r'), delimiter=';'))
print(tb(fields, headers=['Car name', 'How many on road', 'Country of origin', 'Last update data', 'How many left', ''])