Error suggests that file doesn't use encoding UTF-8
but ie. Latin1
, CP1250
, etc. and you may need read_csv(...., encoding='latin1')
If all files use the same encoding - ie. latin1
- then you may need
map(lambda name:pd.read_csv(name, encoding="latin1"), files)
but if files may use different encoding then you may need to use normal for
-loop to run read_csv()
in try/except
to catch problem and run read_csv()
again with different encoding.
Something like this:
# --- before loop ---
all_df = []
# --- loop ---
for name in files:
for encoding in ['utf-8', 'latin1', 'cp1250']:
try:
df = read_csv(name, encoding=encoding)
all_df.append(df)
break
except:
pass
else: # special construction `for/else` - it is executed when `break` wasn't used inside `for`-loop
print("I can't read file:", name)
# --- after loop ---
df = pd.concat(all_df, ignore_index=True)