当某些文件中不存在某些列(例如“国家”)时,如何防止错误?
import csv
files = glob.glob ('..\\*.csv')
for file in files:
countries = []
with open ('data.csv', newline='') as infile:
reader = csv.DictReader(infile)
for row in reader:
countries.append(row['Country'])
print (countries)