【发布时间】:2019-08-02 23:20:03
【问题描述】:
提供示例后,问题会变得更加清晰。 我有一个包含两列的数据框,一列类型为字符串,一列类型为整数:
Col1 Col2
-------------
str1 2
str2 4
str3 1
现在我需要一个列表,其中包含 Col1 中的字符串乘以 Col2 中的数字,即['str1', 'str1', 'str2', 'str2', 'str2', 'str2', 'str3']。
最有效的方法是什么?
【问题讨论】:
-
np.repeat(df['Col1'], df['Col2']). -
哇,真快。就这样,谢谢!
标签: python pandas list dataframe