user12762382
user12762382

Reputation:

Wrong filepath in pandas

I try to get all the csv files from my folder.

I did this with :

currentfile = glob.glob("pathwheremycsvare')

so in the variable currentfile there is now a list of all pathnames of the csv files. (Currently there is only one file for testing.)

Now I try to put it to the pandas.read_csv function:

readcsv=pd.read_csv(currentfile)

But I get this exception:

ValueError: Invalid file path or buffer object type: <class 'set'>

How can I fix this?

Edit:

tried: path = r"pathname\*.csv" for fname in glob.glob(path): print(fname)

It prints me all the csv files with the path.

now I need a foor loop, which executes the rest of the Programm with each csv.

I ll try it with a for loop...

Upvotes: 0

Views: 390

Answers (1)

Naazneen Jatu
Naazneen Jatu

Reputation: 546

As you mentioned, currentfile is a list of all pathnames of the csv files. And pd.read_csv takes file name to read file. Not a list of file names. Like, pd.read_csv('filename.csv') Or you can iterate over currentfile Like

for file in currentfile:
   pd.read_csv(file)

Hope that helps!

Upvotes: 1

Related Questions