Error when trying to import multipe csv files into pandas

时间:2019-03-06 11:31:51

标签: pandas csv python-import multiple-files

I am trying to read several csv files from a directory into pandas and concatenate them into one big DataFrame but I have this error:

OSError: Initializing from file failed

Here is my code

import pandas as pd
import glob

path = r'C:/Users/chris/Downloads/Séance2/horodateurs-transactions-de-  paiement' 
all_files = glob.glob(path + "/*.csv")
transac = pd.DataFrame()
li = []

for filename in all_files:
   df = pd.read_csv(filename, index_col=None, header=0)
   li.append(df)

transac = pd.concat(li, axis=0, ignore_index=True)

I don't know why it doesn't work. I tried to solve the problem by using chmod but anything has changed

1 个答案:

答案 0 :(得分:0)

我也遇到了类似的问题。事实证明文件没有任何权限,并且熊猫未显示正确的错误消息。

ls -lh total 152M -rw-rw-r-- 1 iamsam iamsam 3.4K Nov 6 21:34 quora_insincere_question_GUSE+LSTM.ipynb ---------- 1 iamsam iamsam 34M Feb 6 2019 test.csv ---------- 1 iamsam iamsam 119M Oct 30 2018 train.csv

一旦我授予的读取许可,它就可以很好地工作。

在linux上运行以下命令:chmod 700 filename OR chmod 700 -R directoryname (to change for all the files in that directory.)

在此之后,pd.read_csv()应该可以正常工作。