开始错误的代码段:
1.用lamda根据Program进行修改,其中错误的是没有意识到lambda用法,其中的x就是program,
df['first_url'] = df['Program'].apply(lambda x:"http://www.manmankan.com/dy2013/dianshiju/search.shtml?KeyWords={}&t=2"\
.format(urlencode({df['Program']:x})))
其中urlencode需要进行字典赋值,选择keyword:x赋值后还要在原字段中删除keyword以防重复
df['Program'].apply(lambda x: "http://www.manmankan.com/dy2013/dianshiju/search.shtml?{}&t=2" \
.format(urlencode({'Keywords': x})))
2;采用for循环,一个个quote过去进行赋值,这里错误在first_url不多的覆盖在前一个值
for i in df['Program']:
a = quote(i)
df['first_url'] = "http://www.manmankan.com/dy2013/dianshiju/search.shtml?KeyWords={}&t=2".format(a)
应该给予index进行有序排列
for i in df['Program'].index:
a = quote(df.loc[i,'Program'])
df.loc[i,'first_url'] = "http://www.manmankan.com/dy2013/dianshiju/search.shtml?KeyWords={}&t=2".format(a)