python - 如何将一系列 str 列表与一系列 str 连接起来

标签 python pandas

从字符串列表的 Series 和字符串的 Series 开始,创建列表的 Series,其中每个列表的每个元素都是与第二个Series的相应元素连接。

例如,

series1 = pd.Series([['a','b','c'],['d','e']])
series2 = pd.Series(['1','2'])

这样series3看起来像:

0   [a1, b1, c1]
1       [d2, e2]

最佳答案

在 pandas 中处理列表列时,您已经决定放弃性能。这是您可能获得的最快方法,使用列表理解

pd.Series(
    [[k + j for k in i] for i, j in zip(series1, series2)]
) 

0    [a1, b1, c1]
1        [d2, e2]
dtype: object

关于python - 如何将一系列 str 列表与一系列 str 连接起来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49200873/

相关文章:

python - 添加重复序列值的列

python - 简单的Python消息编码器/解码器问题

python - 峰态,条形图的偏度? - Python

python - 在 flask 的 jsonify() 中缩小 JSON

python - 使用 Pandas 将多个 csv 文件加入一个文件夹中 [MemoryError :]

python - 按标签对多索引数据帧进行分组以计算平均值

python - 如何在类的初始属性中制作空列表?

python - 根据列的条件从单个数据帧中提取多个不同的数据帧

Python pandas 如何将多行合并为一行?

python - 使用 xlrd 引擎在 xls 文件上调用 pands read_excel 时出现 AssertionError