python - 按间隔拆分行 Pandas
问题描述
我的数据
Start End Length Number of Sections
0.01 0.03 0.02(End- Start) 0.02/0.01=2.0
0.00 0.05 0.05 0.05/0.01=5.0
我希望我的输出是
Start End Length Number of Sections
0.01 0.02 0.01 1.0
0.02 0.03 0.01 1.0
0.00 0.01 0.01 1.0
0.01 0.02 0.01 1.0
0.02 0.03 0.01 1.0
0.03 0.04 0.01 1.0
0.04 0.05 0.01 1.0
试过很多次了,请给点建议
bounds=np.unique(np.hstack((df["StartMilepost"],df["EndMilepost"])))
df2=pd.DataFrame({"StartMilepost":bounds[:-1],"EndMilepost":bounds[1:]})
isin=df.apply(lambda x :
df2['StartMilepost'].between(int(x[0],x[1]-1))
| df2['EndMilepost'].between(int(x[0]+1,x[1]),axis=1)).T
data=np.where(isin,df.NumberofSections,0)
df3=pd.DataFrame(data,
pd.MultiIndex.from_arrays(df2.values.T),df["min"])
解决方案
推荐阅读
- python-3.x - Python3在findall中使用带有正则表达式的f-string
- css - HTML iframe 在动画期间显示滚动条然后消失。CSS 溢出属性设置为隐藏
- sql - 如何从每个月内多次出现的重复值中选择 MAX(VALUE)?
- statistics - 关联规则挖掘的提升(兴趣)度量的统计意义
- javascript - 第二次查询执行出错时如何回滚| 节点JS
- bash - 如何在我的仓库中找到最后一行有特定单词的每个文件?
- xcode - Safari 扩展 CSS 注入未加载
- javascript - 可以在数组中使用 x 吗?
- javascript - javascript中立即调用的函数表达式
- git - 如何返回提交修复/补丁,但之后不更改任何内容?