特定列的熊猫中的vlookup
我在熊猫中使用合并功能面临一些困难。我正在为此寻找某种vlookup公式。但是,我无法解决问题。
我的数据很大,由于机密性,我无法在这里共享。但是,我尝试在这里提出类似的数据。
旧代码 | 新代码 | 名称 | 发票日期 |
---|---|---|---|
1001011 | NA | 奶酪蛋糕 | 02/02/2021 |
1001012 | NA | Coffee | 03/05/2021 |
1001011 | NA | 奶酪蛋糕 | 30/05/2021 |
NA | 2002093 | Jasmine | 21/08/2021 |
NA | 2002042 | COOKIE | Tea |
NA | 2002080 | 咖啡 | 09/01/2022 |
NA | 2002093 | Jasmine Tea | 05/05/2022 |
NA | 2002058 | 奶酪蛋糕 | 07/06/2022 |
我想在上表中的成本列输入。但是,成本非常按发票日期(也请注意更改产品代码)。我们有2个成本表。 2021年:
旧代码 | 新代码 | 名称 | JAN 21 | 年2月21日 | , | 3月21日4 | 月21日, | 6 | 月21日,6月21日,7月21日, | 21日 | 8月21日,8月21日,9月 | , 10月21日 | ,11月21日 | ,12月21日 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1001011 | 200201152058 | 奶酪蛋糕 | 50 | 51 | 50 | 53 | 54 | 52 | 55 | 53 | 50 52 | 53 | 53 | 53 |
1001012 | 2002080 | 咖啡 | 5 | 6 | 5 | 6 | 5 | 7 | 5 | 6 | 5 | 6 | 5 6 6 | 6 |
1001015 | 2002093 | 茉莉茶 | 4 | 3 | 3 | 4 | 4 | 3 | 3 | 3 | 3 3 | 3 | 3 3 3 | 4 |
1001020 | 200202002042 | cookies | 20 | 20 21 | 20 20 | 22 22 | 22 | 20 | 21 | 20 | 20 22 | 20 | 21 | 22 |
和2022年:
旧代码 | 新代码 | 名称 | Jan-22 | Feb-22 | Mar-22 | 4 | 月22日,4月22日,6月 | 22日,7月22日,8月22日, | 8月22日, | 9月22日 | ,10月22日 | ,10月22 | 日22 | Dec-22 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1001011 | 2002058 | 奶酪蛋糕 | 52 | 52 | 55 | 55 | 56 | 52 | Na Na Na Na Na Na Na Na Na Na | Na | Na | Na Na Na | Na Na | Na |
1001015 | 2002093 | Na Na Na Na Na Na Na Na Na Na Na Na | 5 5.5 | Na | Na | Na | Na | Na | Na Na | Na | Na Na | Na Na Na Na | Na Na | Na Na |
5.5 | 5 5.5 5 5.5 | Jasmine Tea | 4 | 3 | 3 | 5 5.5 5 | 5.5 5 | 5.5 | 5 | 5.5 | 5 5.5 | 5 | Na Na | NA |
1001020 | 2002042 | Cookies | 22 | 22 | 23 | 23 | 23.5 | 23 | NA | NA | NA | NA | NA | NA |
So basically, I would like to have my cost column in my first Data Frame to reflect the correct costing for different Year and different Month.
示例:
03/05/2021 = May_2021的发票日期成本
I am facing some difficulties using merge function in Pandas. I am looking for some kind of Vlookup formula for this. However, I couldn't solve my problem.
My data is huge and I couldn't share here due to confidentiality. However, I try to came up with similar data here.
Old Code | New Code | Name | Invoice Date |
---|---|---|---|
1001011 | NA | Cheese Cake | 02/02/2021 |
1001012 | NA | Coffee | 03/05/2021 |
1001011 | NA | Cheese Cake | 30/05/2021 |
NA | 2002093 | Jasmine Tea | 21/08/2021 |
NA | 2002042 | Cookies | 31/12/2021 |
NA | 2002080 | Coffee | 09/01/2022 |
NA | 2002093 | Jasmine Tea | 05/05/2022 |
NA | 2002058 | Cheese Cake | 07/06/2022 |
I would like to have a COST Column input in my table above. However, the cost is very by invoice date (Also take note on the changing of product code). We have 2 cost table.
For year 2021:
Old Code | New Code | Name | Jan-21 | Feb-21 | Mar-21 | Apr-21 | May-21 | June-21 | Jul-21 | Aug-21 | Sep-21 | Oct-21 | Nov-21 | Dec-21 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1001011 | 2002058 | Cheese Cake | 50 | 51 | 50 | 53 | 54 | 52 | 55 | 53 | 50 | 52 | 53 | 53 |
1001012 | 2002080 | Coffee | 5 | 6 | 5 | 6 | 6 | 5 | 7 | 5 | 6 | 5 | 6 | 6 |
1001015 | 2002093 | Jasmine Tea | 4 | 3 | 3 | 4 | 4 | 3 | 5 | 3 | 3 | 3 | 3 | 4 |
1001020 | 2002042 | Cookies | 20 | 20 | 21 | 20 | 22 | 20 | 21 | 20 | 22 | 20 | 21 | 22 |
And also for Year 2022:
Old Code | New Code | Name | Jan-22 | Feb-22 | Mar-22 | Apr-22 | May-22 | June-22 | Jul-22 | Aug-22 | Sep-22 | Oct-22 | Nov-22 | Dec-22 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1001011 | 2002058 | Cheese Cake | 52 | 52 | 55 | 55 | 56 | 52 | NA | NA | NA | NA | NA | NA |
1001012 | 2002080 | Coffee | 5 | 6 | 5 | 6 | 6 | 6.5 | NA | NA | NA | NA | NA | NA |
1001015 | 2002093 | Jasmine Tea | 4 | 3 | 3 | 5 | 5 | 5.5 | NA | NA | NA | NA | NA | NA |
1001020 | 2002042 | Cookies | 22 | 22 | 23 | 23 | 23.5 | 23 | NA | NA | NA | NA | NA | NA |
So basically, I would like to have my cost column in my first Data Frame to reflect the correct costing for different Year and different Month.
Example:
Invoice Date Costing for 03/05/2021 = May_2021
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
合并时,您需要双方都有一个月和代码编号,因此:
You need to have the month and code number on both sides when merging, so: