如何将2个数据帧与不同键合并
您能在下面提供我的案例吗?我想合并2个数据集,以获取以下预期结果:
DF 1:一个数据框总结每个ID的功能的值如下:
ID | 功能1 | 功能2 |
---|---|---|
1 | 1.2 | 3.4 |
2 | 2.3 | 1.2 3 1.2 |
3 | 3.5 | 6 |
DF 2:将表映射到根据每个功能的最小/最大阈值确定每个功能的相应段 |功能| min | max |细分| | - | --- | --- | --- | |功能1 | 0 | 1 | 1 | |功能1 | 1 | 2 | 2 | |功能1 | 2 | Inf | 3 | |功能2 | 0 | 4 | 1 | |功能2 | 4 | 5 | 2 | |功能| 5 | Inf | 3 |
预期结果:我想将DF1与df2中的映射表合并以获得相应的段
ID | 功能1 | 功能1 | 功能1特征1片段 | 功能2段 |
---|---|---|---|---|
1 | 1.2 | 3.4 | 2 | 1 |
2 | 2.3 | 1.2 3 1.2 | 3 | 1 |
3 | 3.5 | 3 3.5 6 3 3 | 3 3 | 3 |
感谢很多帮助。
Can you please help on my case as below. I want to merge 2 dataset to get the expected results as below:
Df 1: A data frame summarises value of features of each ID as below:
id | feature 1 | feature 2 |
---|---|---|
1 | 1.2 | 3.4 |
2 | 2.3 | 1.2 |
3 | 3.5 | 6 |
Df 2: Mapping tables to determine corresponding segment for each feature based on min/max thresholds of each features
|Feature|Min |Max|segment|
|--| --- | --- |---|
|Feature 1 | 0 |1|1|
|Feature 1 |1|2|2|
|Feature 1 |2 |inf|3|
|Feature 2 | 0 |4|1|
|Feature 2 |4|5|2|
|Feature |5 |inf|3|
Expected results: I want to merge df1 with mapping table in df2 to get corresponding segment
id | feature 1 | feature 2 | feature 1 segment | feature 2 segment |
---|---|---|---|---|
1 | 1.2 | 3.4 | 2 | 1 |
2 | 2.3 | 1.2 | 3 | 1 |
3 | 3.5 | 6 | 3 | 3 |
Thanks a lot for helps
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这里输出
,首先将“ ID”列设置为索引。创建一个“ func_data”功能来确定每个数字落入哪个范围。 np.的函数来自numpy的范围。通过“ ID”获取索引。
Output
Here, first the 'id' column is set as an index. A 'func_data ' function is created to determine which range each number falls into. The np.where function from numpy is used to test for a range. Get indexes by 'id'.