如何将temp_list分配给“PLAYERS”列中的每个元素?
temp_list =['a','b']
DATE COUNTRY COUNTRY_ID COUNT PLAYERS
0 1980 United States 840 42 0
1 1980 Czech Republic 203 2 0
2 1980 New Zealand 554 3 0
3 1980 Italy 380 4 0
4 1980 Paraguay 600 2 0
5 1980 Brazil 76 3 0
6 1980 Chile 152 2 0
答案 0 :(得分:1)
创建一个长度与数据帧相同的列表列表并分配它?
In [685]: df['PLAYERS'] = [temp_list] * len(df.index)
In [686]: df
Out[686]:
DATE COUNTRY COUNTRY_ID COUNT PLAYERS
0 1980 United States 840 42 [a, b]
1 1980 Czech Republic 203 2 [a, b]
2 1980 New Zealand 554 3 [a, b]
3 1980 Italy 380 4 [a, b]
4 1980 Paraguay 600 2 [a, b]
5 1980 Brazil 76 3 [a, b]
6 1980 Chile 152 2 [a, b]