0

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

1 Answer 1

0

I also ran into same kind of problem. It turned out the files didn't have any permission and pandas was not showing proper error message.

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

Once I gave the read permission the, it did work well.

run this command on linux : chmod 700 filename OR chmod 700 -R directoryname (to change for all the files in that directory.)

After this pd.read_csv() should work fine.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.