简体   繁体   English

使用Glob,OS使用熊猫读取CSV文件时出错

[英]Error when using glob, os to read csv files using pandas

I'm trying to read multiple csv files in a directory, using pandas. 我正在尝试使用pandas读取目录中的多个csv文件。 I used two methods, and both are not working. 我使用了两种方法,但两种方法均无效。

import os
from glob import glob
from math import*
from numpy import*
from pandas import*


path = '/Volumes/File/Names/Stuff 2016'


for filename in glob(os.path.join(path, '*.csv')):
    qu = read_csv(filename, delimiter = ';', header = 0, skiprows = 24, nrows=2)
    print(qu)

Edit:(The above code works.) 编辑:(上面的代码有效。)
Below when I try to just read all files in that specific path, without specifying it's a csv: 下面,当我尝试仅读取该特定路径中的所有文件而未指定为csv时:

for filename in os.listdir(path):
    q = read_csv(filename, delimiter = ';', header = 0, skiprows = 24,  nrows=2)

FileNotFoundError: File b'STD_20160103.00.csv' does not exist 

This error is confusing me, since that specific file does exist in the directory. 此错误使我感到困惑,因为该目录中确实存在该特定文件。 I'm wondering if the file names '*.00.csv' are the problem, but I just want to print the values along all the files, and it's not working. 我想知道文件名'* .00.csv'是否是问题,但我只想在所有文件中打印值,但它不起作用。 Thanks 谢谢

glob returns the full path ... os.listdir only returns the filenames glob返回完整路径... os.listdir仅返回文件名

so change it to 所以将其更改为

q = read_csv(os.path.join(path,filename),...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM