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

riya
  • 130
  • 1
  • 9

2 Answers2

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)
Barmar
  • 741,623
  • 53
  • 500
  • 612
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)
JoKing
  • 430
  • 3
  • 11