python - Python:将代码应用于整个数据框列
问题描述
我在一个填充有值的数据框中有一列 col1。
col1
row1 [0.0, 6.33839991, 3.93961207, 5.27702178, 8.27702178, 6.44343, 5.668574]
row2 [0.0, 5.93961207, 4.27702178, 4.12702178]
row3 [0.0, 6.44428501, 3.93961207, 8.27702178, 4.27121178]
每行包含一个系列。我需要一个新列,比如 col2,它返回一个新系列。该系列从 0 开始,每次递增 100,直到该系列与原始系列的长度相匹配。
预期产出
col1 col2
row1 [0.0, 6.3, 3.93, 5.27, 8.2, 6.4, 5.6] [0,100,200,300,400,500,600]
row2 [0.0, 5.9, 4.2, 4.1] [0,100,200,300]
row3 [0.0, 6.4, 3.9, 8.2, 4.2] [0,100,200,300,400]
谢谢!
解决方案
我的主张是:
df['col2'] = df.col1.transform(lambda x: [ i * 100 for i in range(len(x))])
推荐阅读
- java - 在 iText7 中创建 PdfTextFormField 专门用于数字输入
- android - android 应用程序是否可以使用 manifest.xml 文件中未声明的权限?
- c++ - 使用 WM_TIMER 绘制分段连续函数
- reactjs - 远程调试时反应本机组件不会更新
- stripe-payments - 分条付款 - 单次收费的最高金额为 $999,999.99
- python-3.x - 在 python 中使用 cv2.drawcontours() 时出错
- javascript - ES6 功能不可用
- angular - 从 Cordova android 应用程序下载 .xlsx 文件的问题
- c# - 将浮点数转换为货币字符串
- c# - 如何检查表中显示的品牌名称是否按特定顺序