我在python列表中将float转换为int时遇到了问题。在
列表中的一个元素如下所示:{'artForm': 'Madur',
'artistName': 'Bharati Dolai',
'gender': 'F',
'district': 'Paschim Medinipur',
'phone': '',
'artisanCard': {'exists': 'N', 'cardNo': ''},
'dob': '',
'age': 45.0,
'year': 1971.0,
'education': 'I',
'childrenGoToSchool': 'Y'
}
我无法将age和year转换为int
我的代码:
^{pr2}$
我得到以下错误ValueError: cannot convert float NaN to integer
期望输出:{'artForm': 'Madur',
'artistName': 'Bharati Dolai',
'gender': 'F',
'district': 'Paschim Medinipur',
'phone': '',
'artisanCard': {'exists': 'N', 'cardNo': ''},
'dob': '',
'age': 45, #converted to int
'year': 1971, #converted to int
'education': 'I',
'childrenGoToSchool': 'Y'
}