I have a bunch of csv files in a folder that I have saved into a dictionary so that each entry is its own dataframe. Each dataframe is a few columns of time series data.
for df in csv_files:
df_name = df
filename = "{}".format(df)
#print(filename)
dfs[df_name] = pd.read_csv(filename, sep = ',', skiprows= 13)
dfs[df_name].loc[0] = 0 # set first line to zeros
All of the dictionary keys right now are the name of the data file so if I want to look at just one dataframe I have to type in the whole path.
dfs['/content/drive/My Drive/LAICPMS 72123/ANP/ANP 072123_7.csv']
But this isn't very convenient. I'm able to change each key manually as follows
dfs['7'] = dfs.pop('/content/drive/My Drive/LAICPMS 72123/ANP/ANP 072123_7.csv')
but I'd really like to use a loop to rename each key as a string integer.
I tried to make a list of string integers by counting the number of files in the folder
#how many files are in folder
count = 0
for path in listdir("/content/drive/My Drive/LAICPMS 72123/ANP"):
if isfile(join("/content/drive/My Drive/LAICPMS 72123/"ANP, path)):
count+=1
#print(count)
#make a list of integer as long as number of files
num_files = list(range(count))
#convert integers to strings
list_st = map(str, num_files)
#print(list(list_st))
for x in list_st:
print(x)
which successfully counts them and makes a new list, but then I'm lost on how to set up a loop to rename the dictionary keys with this list. Clearly, I'm not understanding something about indexing lists and dictionaries.