选择o对应于列和行之间的交点的值
PRODUCT VALUE NUMBER OF PAYMENTS
最小值最大值 | 1 | 至6 | 7至11 |
---|---|---|---|
500 | 1000 | 2% | 4% |
1001∞3 | 利息 | % | 5% |
这是付款%利息表的一小部分(实际表为5x5),我需要选择之间的 最终我用有条件的---- 进行了一个价值和许多付款分期付款,这是81行代码,对我来说还可以,但是我一直在想是什么是“专业解决方案”使用表,熊猫或numpy。
例如,如果我的产品售价1500美元,2付款,我的利率将为3%
PRODUCT VALUE NUMBER OF PAYMENTS
MIN VALUE | MAX VALUE | 1 TO 6 | 7 TO 11 |
---|---|---|---|
500 | 1000 | 2% | 4% |
1001 | ∞ | 3% | 5% |
This is a small sample of the table of % interest to pay (the actual table is 5x5), I need to select the interest between a value and a number of payment installments, eventually I did with conditional---- were 81 lines of code, well for me it was ok, but I kept thinking what would be the "professional solution" using tables, pandas or numpy.
For example if my product cost 1500 USD, With 2 payments my interest rate would be 3%
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用熊猫很容易。用大整数(例如1000000)替换
max value
(其中是∞
),然后您可以使用以下方式选择适当的行:困难的部分是从那排。一种方法是创建从列名创建范围:
然后,您可以从该词典中选择列:
最后您可以使用行和列索引找到所需的值:
output:
注意:鉴于桌子的尺寸很小,您可以通过为每个付款价值的单独列来使生活更轻松。然后,您可以简单地做:
Using pandas the first part is easy. Replace
MAX VALUE
(where it is∞
) with a large integer (e.g. 1000000) and then you can select the appropriate row using:The hard part is selecting the appropriate column from that row. One way to do that would be to create ranges from the column names:
Then you could select the column from that dictionary:
Finally you can find the value you want using the row and column indexes:
Output:
Note: given the small size of your table, you could make your life much easier by having a separate column for each number of payments value. Then you could simply do: