【发布时间】:2021-12-16 15:47:44
【问题描述】:
大家早上好。 我想使用第二个数据框中的数据在我的主数据框中创建一个分箱列。 Dataframe#1 具有“Runner ID”和“Cumulative Distance”列。 Dataframe#2 具有“Runner ID”、“Section Start”和“Section Name”列 我正在尝试根据两个数据帧中匹配的“Runner ID”在 Dataframe#1 上创建名为“Section Name Binning”的第三列,然后使用“Section Start”列中的数据从 Dataframe#1 中分箱“累积距离”和 Dataframe#2 中的“部分名称”。 Dataframe#1 的“Cumulative Distance”和 Dataframe#2 的“Section Start”将始终按递增顺序排列,并在“Runner ID”更改时重新启动。 附上一张图片和数据框示例。 一如既往地感谢您的支持。
df1=pd.DataFrame({'Runner_ID':['John','John','John','John','John','John','John','John','John','John','John','Jen','Jen','Jen','Jen','Jen','Jen','Jen','Jen','Jen','Jen','Jen'],'Cumulative_Distance':[1,1.5,1.8,3,3.2,3.7,4,4.3,5,6.6,8,2,2.3,2.8,3.2,3.5,3.9,4.8,5,5.3,5.8,6]})
df2=pd.DataFrame({'Runner_ID':['John','John','John','Jen','Jen','Jen','Jen'],'Section_Start':[0,3,5,0,2.5,3.5,5], 'Section_Name':['Flats', 'Uphill', 'Downhill', 'Flats', 'Uphill','Curve', 'Downhill']})
【问题讨论】: