如何从文件中导入csv数据
如何从文件中导入csv数据
这个问题已经有了答案:
在一个目录里,我有大约100个文件- csv数据。如何将它们导入到Python中?我进行了搜索并找到了:
import csv f = open("imgdata.csv") r = csv.reader(f) f.close()
但它对于一个目录不起作用。这与查找文件无关,而是与导入它们有关。
admin 更改状态以发布 2023年5月20日
使用glob
:
import glob import csv for f_name in glob.glob("*.csv"): with open(f_name) as f: reader = csv.reader(f) # do stuff here