Please, before marking this question as duplicated read the whole post. I know that this post has a similar question but what I'm looking for is somehow different.
I have a list of file names:
files = ['first.csv', 'second.csv', 'third.csv']
And I want to read them inside a loop with pandas. What I expect is to create for each iteration inside the loop a different dataframe:
first = pd.read_csv('first.csv')
second = pd.read_csv('second.csv')
third = pd.read_csv('third.csv')
But inside a loop. Something like:
for i in range(len(files)):
csv = re.split('.', files[i])[0]
csv = pd.read_csv(files[i])
IMPORTANT: Each csv has different rows and columns. So what I want is not to read the three csv to combine them into one with pd.concat. I want to read them separately.
I tried to read them into a list with:
dataframe_list = [pd.read_csv(file_name) for file_name in files]
But that raises the next error:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x85 in position 59: invalid start byte
third.csv? It sounds like they want three different dataframes.frames=[pd.read_csv(f) for f in files]or evenframes=list(map(pd.read_csv, files)).except UnicodeDecodeError:and then try reading the bad files with the added argumentencoding='latin-1'withinpd.read_csv