from csv import reader
# Read the `artworks_clean.csv` file
opened_file =open('artworks_clean.csv', encoding='utf-8')
read_file = reader(opened_file)
moma =list(read_file)
moma = moma[1:]# Convert the birthdate valuesfor row in moma:
birth_date = row[3]if birth_date !="":
birth_date =int(birth_date)
row[3]= birth_date
# Convert the death date valuesfor row in moma:
death_date = row[4]if death_date !="":
death_date =int(death_date)
row[4]= death_date
# 请在此添加代码,创建字典然后打印结果#********** Begin **********#for row in moma:
date = row[6]if date !="":
date =int(date)
row[6]= date
print(type(moma[100][6]))#********** End **********#
第2关:计算艺术家年龄
from csv import reader
# Read the `artworks_clean.csv` file
opened_file =open('artworks_clean.csv', encoding='utf-8')
read_file = reader(opened_file)
moma =list(read_file)
moma = moma[1:]# Convert the birthdate valuesfor row in moma:
birth_date = row[3]if birth_date !="":
birth_date =int(birth_date)
row[3]= birth_date
# Convert the death date valuesfor row in moma:
death_date = row[4]if death_date !="":
death_date =int(death_date)
row[4]= death_date
# Convert the date valuesfor row in moma:
date = row[6]if date !="":
date =int(date)
row[6]= date
# 请在此添加代码,计算艺术家年龄然后打印结果#********** Begin **********#
ages=[]
final_ages=[]for row in moma:
date = row[6]
birth = row[3]iftype(birth)==int:
age = date - birth
else:
age =0
ages.append(age)for a in ages:if a >20:
final_ages.append(a)else:
final_ages.append('Unknown'