这是我的数据:
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)
目前没有回答
相关问题 更多 >
编程相关推荐