0

Several posts explain how to loop through a folder, or to extract all (or:specific) files from a given zip, or to create a pandas data frame from several CSVs in a file. Alas I am lacking experience to combine all these code snippets into something that works - Can someone help me, please?

What I currently have:

import gzip
import csv
import json
import pandas as pd

path =r'C:\\Users\\folder_with_zipped_files' 
File_List= glob.glob(path + "/*.csv.gz")
frame = pd.DataFrame()
list_ = []
for file_ in File_List:
    df = pd.read_csv(File_List, compression='gzip', header=0,sep=',',  error_bad_lines=False)
    collectfiles.append(df)
allfiles = pd.concat(collectfiles)

This throws the Error:

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

Thanks a million for any advice and help -it's much appreciated!

ReKx
  • 996
  • 2
  • 10
  • 23
user2006697
  • 1,107
  • 2
  • 11
  • 25
  • 1
    You're passing the list not the filepaths in your list, you want `df = pd.read_csv(file_,....` – EdChum Jun 25 '18 at 15:31
  • @user2006697, I am linking to a duplicate which has precisely the same method you are attempting. Note that your `collectfiles` doesn't seem to be defined anywhere. – jpp Jun 25 '18 at 15:33

0 Answers0