0

I'm sure there must be a simple way of doing this. I have a loop that opens all files in the folder with time in the title, and I want to be able to open each one as a DataFrame with the name of the file that I opened as the title of the DataFrame. Currently, the only way I know of naming a DataFrame is creating it (i.e. inf1 = pd.read_csv(fname)) and obviously inf1 is not a spectacularly useful name, plus each time the loop runs inf1 is overwritten.

Thanks in advance!

itzmurd4
  • 663
  • 10
  • 25
J.Komodo
  • 101
  • 9
  • 1
    Why don't you create a dictionary? i.e. `dct[fname] = pd.read_csv(fname)` – Firman Sep 12 '17 at 14:10
  • I'm assuming I just don't understand dictionaries then, as I've only seen them created manually and I need it to be automatic, as I don't know the amount or names of the variables beforehand. I was hoping there was something simple I could do with a list, or just rename the DataFrame afterwards using fname, but that doesn't seem to work. – J.Komodo Sep 12 '17 at 14:23
  • Note: having looked at dictionaries and totally failed to understand them, a simple way round this is just to do whatever you need to the files and save them as csv at the end again, as in inf1.to_csv(fname + ' reindexed.csv'). – J.Komodo Sep 12 '17 at 14:32

0 Answers0