• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Multiply by a different number of columns with iloc in Pandas

Resolved: Multiply by a different number of columns with iloc in Pandas

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I have the following dataframe:
The dX_real refers to the actual values on day 3, day 7, and day 14… and the second one is each multiplier for that specific day.
I want to calculate those predictions in the following way. First, I take the target column (d3_real, d7_real…) and then I multiply it for each multiplier depending on the case. for example, to calculate the prediction from d3_real to d30, I would need to multiply it by the multipliers of D7, D14 and D30.
Is there any way to automate this with a loop? I do not know how to multiply each dX_real column without using conditional for each case as the number of multiplications changes.
This is what I have tried that it is not working as expected, as it is only multiplying the first multiplier:
However, from here, I do not know how to specific which values it needs to multiply based on d3, d7 and d14.
Thanks!

Answer:

Output
Here the first loop selects the names of the new columns from the ‘ddd’ list and sets the first value in the new column. In the nested loop, the numbers of the desired columns are taken from the list ‘bbb’ and the values are multiplied. Check with your data or show the expected result with your example. You need to check for a match.

If you have better answer, please add a comment about this, thank you!

dataframe pandas python
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Azuer Service Bus SDK not receiving the specified messages

01/04/2023

Resolved: how to change date format from 201904 to Apr-19 in excel

01/04/2023

Resolved: Iterator for custom Hashtable C#

01/04/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.