1
import csv
import pandas

df_list = []
path = "C:/Users/bubai/Desktop/try/scrapy/output"
#all csv file
for file in os.listdir(path):
    #print(file)
    df_list.append(file)  # all csv file in this
#print(df_list) 
for i in df_list:
    df = pandas.read_csv(i)  # open one by one 
    print(df)

I have some error:-FileNotFoundError: [Errno 2] File b'poem1.csv' does not exist: b'poem1.csv' file name are saved like poem1.csv poem10.csv poem11.csv poem12.csv poem13.csv poem14.csv poem15.csv poem16.csv poem17.csv poem18.csv poem19.csv poem2.csv poem20.csv

4
  • try this , df_list.append(path + '/' + file) Commented Jun 15, 2020 at 18:48
  • thank you man.... its works Commented Jun 15, 2020 at 18:50
  • This solution may be what you are looking for: <stackoverflow.com/a/21232849/12762476> Commented Jun 15, 2020 at 18:51
  • can you explain this Commented Jun 15, 2020 at 18:51

2 Answers 2

2

You need to append the filename to the path.

import csv
import pandas
import os

df_list = []
path = "C:/Users/bubai/Desktop/try/scrapy/output"
#all csv file
for file in os.listdir(path):
    df_list.append(os.path.join(path,file))  # all csv file in this
#print(df_list) 
for i in df_list:
    df = pandas.read_csv(i)  # open one by one 
    print(df)
Sign up to request clarification or add additional context in comments.

Comments

2

You need to concatenate the directory name with the filename in order to refer to the file.

import os

df = pandas.read_csv(os.path.join(path, i)

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.