我有列表lst = ['vk.com', 'facebook.com', 'avito.ru', 'twitter.com']
我想将其添加到此df
:
date id request
2016-06-17 09:26:18 yans.bouts@yandex.ru GET HTTP/1.1
2016-06-17 09:38:18 yans.bouts@yandex.ru GET HTTP/1.1
2016-06-17 10:13:44 yans.bouts@yandex.ru GET HTTP/1.1
2016-06-17 10:19:24 yans.bouts@yandex.ru GET HTTP/1.1
我尝试df.append
,但它不起作用。
答案 0 :(得分:4)
如果列表的length
与df
使用的长度相同:
lst = ['vk.com', 'facebook.com', 'avito.ru', 'twitter.com']
df['new'] = lst
print (df)
date id request new
0 2016-06-17 09:26:18 yans.bouts@yandex.ru GET HTTP/1.1 vk.com
1 2016-06-17 09:38:18 yans.bouts@yandex.ru GET HTTP/1.1 facebook.com
2 2016-06-17 10:13:44 yans.bouts@yandex.ru GET HTTP/1.1 avito.ru
3 2016-06-17 10:19:24 yans.bouts@yandex.ru GET HTTP/1.1 twitter.com