码迷,mamicode.com
首页 > 其他好文 > 详细

列处理——变形

时间:2016-01-05 22:15:09      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:

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

 

列处理——变形

标签:

原文地址:http://www.cnblogs.com/arsh/p/5103675.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!