简体   繁体   English

如何为Pandas列中的每个元素分配一个列表(或系列)?

[英]How can I assign a list (or series) to every element in column in Pandas?

How can I assign temp_list to every element in the column "PLAYERS"? 如何为“ PLAYERS”列中的每个元素分配temp_list?

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

Create a list of lists with length same of dataframe and assign it? 创建长度与数据帧相同的列表列表并分配它?

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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在熊猫数据框中选择系列中每个元素均符合条件的序列? - How can I select series in a pandas dataframe where every element in the series meets a criterion? 如何有效地将系列索引添加到Pandas系列列表数组的每个列表元素中? - How can I add the series index to each list element a Pandas series of arrays of lists efficiently? 如何将 pandas.core.series.Series 分配给 pandas dataframe 列 - how to assign a pandas.core.series.Series to a pandas dataframe column 如何将 Pandas 系列指定为列名? - How to assign Pandas series as column names? 如何将多列分配给一系列列表熊猫 - How to assign multiple columns to a series of list pandas 如何将 function 应用到 Pandas 中的一系列其他行? - How can I apply a function to every other row in a series in Pandas? 如何为 Pandas 数据框中的列表列中的每个元素添加双引号? - How do I add double quotes to every element in a list column in a pandas dataframe? 如何将 pandas.series.str.contains 方法的结果分配给新列 - How do I assign the results of a pandas.series.str.contains method in pandas to a new column 如何获得 pandas 系列的按元素逻辑非? - How can I obtain the element-wise logical NOT of a pandas Series? 如何获得两个熊猫系列文本列的交集? - How can I get intersection of two pandas series text column?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM