列处理——截取

#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])

 

你可能感兴趣的:(列处理——截取)