0

I am trying to read all csv file names in a folder and then create dataframes of the same name as of csv name.

def csv_file_names(path):
    filenames = os.listdir(path)
    return [filename for filename in filenames if filename.endswith(".csv")]

csv_files = csv_files_names(data_path)
for file in csv_files:
    file[:-4] = pd.read_csv(file)

But it's throwing error 'str' object does not support item assignment.

Nilesh
  • 41
  • 7
  • This is really not a good idea. If you want named objects, use a dictionary. Also see http://stupidpythonideas.blogspot.com/2013/05/why-you-dont-want-to-dynamically-create.html – PM 2Ring May 30 '18 at 18:58
  • It throws error in the last line as file[:-4] is a string object which I am trying to use as a dataframe name – Nilesh May 30 '18 at 18:58

0 Answers0