列处理——截取

#input is a list named legislators, the first two elements looks like this:
#[['Bassett', 'Richard', '1745-04-02', 'M', 'sen', 'DE', 'Anti-Administration'], ['Bland', 'Theodorick', '1742-03-21', '', 'rep', 'VA', '']]
#Bassett Richard is the name
#1745-04-02 is bithdate
#M is gender

对生日列做处理

  • 截取有用的部分:年份
birth_years = []
for row in legislators:
    birth_list=row[2].split('-')
    birth_years.append(birth_list[0])
  • 插入新列
for i,row in enumerate(legislators):
    row.append(birth_years[i])

 

posted on 2016-01-05 20:35  arsh  阅读(168)  评论(0编辑  收藏  举报

导航