python - 数据操作 Python - 迭代行
问题描述
这是我的数据:
S.No StartMilepost End Milepost Segment Length
1 0.01 0.03 0.02
我想要这样的输出:
S.No StartMilepost End Milepost Segment Length
1 0.01 0.02 0.01
2 0.02 0.03 0.01
我试过这段代码:
split_rows = (df2['SegmentLength'] / 0.01)
while split_rows.any():
df2.loc[split_rows,'StartMilepost']=df2.loc[split_rows, 'StartMilepost']
#update the end Milepost of old rows
df2.loc[split_rows, 'EndMilepost'] = df2.loc[split_rows, 'StartMilepost']
+0.01
#update the duration of all rows
df2['SegmentLength'] = df2['EndMilepost'] - df2['StartMilepost']
#when job is done:
df2.sort_index().reset_index(drop=True)
df2 = df2.append(new_rows)
解决方案
推荐阅读
- sql - 在 SQL 中的视图上触发 DML 操作
- python-3.x - 尝试构建一个返回中位数的函数,不断收到“索引浮点数而不是整数”错误
- c++ - redis_client::get 需要一秒钟以上才能回复
- java - 在单独的 android:process 上显示插页式广告
- c - 如何将函数的指针返回到指针,C语言
- android - 错误:找不到带有哈希字符串“android-28”的目标
- nginx - nginx url参数重写
- swift - 具有子类类型的类方法调用闭包的基类
- vhdl - 如何在 VHDL 中连接两个模块?
- vba - 如何调用针对除 VBA 中的第一个工作表之外的每个工作表的函数