I have a list of countries with corresponding .csv files. When I attempt to read_csv iterated over the list with a for loop, I get an error.
I tried generating an empty dict first and making a dict of dataframes, I tried using decode
, I tried using item = r'{}.csv'.format(file)
instead of just item = '{}.csv'.format(file)
.
import pandas as pd
import string as str
fileslist = []
with open('data/files.txt') as f:
for line in f:
fileslist.append(f.readline().strip())
for file in fileslist:
item = '{}.csv'.format(file)
print(item)
item = pd.read_csv(item)
This should give me a number of dataframes starting with a dataframe named algeria. Instead I get the error "FileNotFoundError: File b'algeria.csv' does not exist".