I have 12 csv files which I wanted to import into a data frame in column wise.
For instance, the each 12 csv files are named differently as follows:
filenames = ['experiment_timesteps_1.csv',
'experiment_timesteps_2.csv',
'experiment_timesteps_3.csv',
'experiment_timesteps_4.csv',
'experiment_timesteps_5.csv',
'experiment_timesteps_6.csv',
'experiment_timesteps_8.csv',
'experiment_timesteps_10.csv',
'experiment_timesteps_12.csv',
'experiment_timesteps_15.csv',
'experiment_timesteps_18.csv',
'experiment_timesteps_20.csv']
I wanted to use the unique file names (11th to the last 4) as column header in a new data frame. Each file consists of a single column with the same number of rows as follows:
results
266430.1827
318881.2395
285411.9195
279878.2699
272394.9219
239213.2243
274932.4677
290705.0974
315464.9616
240384.0452
I encountered the error with the execution of the following code:
results = DataFrame()
for name in filenames:
results[name[11:-4]] = read_csv(name, header=0)
ValueError: Cannot set a frame with no defined index and a value that cannot be converted to a Series