'How can I iterate in my dataframe putting an extra column and a value if some conditions are accomplished?
I have a dataframe with over 8 millions records like this, product promotion It´s what you have to buy to get your reward, accumulation It´s what you have bought.
| Name | Product | Product Promotion | Reward | Accumulation |
|---|---|---|---|---|
| Jhon | Prod1 | 3 | 1 | 3 |
| Casandra | Prod2 | 2 | 1 | 1 |
To cover any situation, I have a code, If some other conditions are met, too far I have a code like this but I´ts taking too long and I´m not getting the results I want to have.
for acummulation, promotion,reward in zip(df["Accumulation"], df["Product Promotion"],df["Reward"]):
if acummulation==reward:
df['ProductToRetire']=Reward
elif acummulation>reward:
df['ProductToRetire']=math.trunc(acummulation/promotion)*Reward
else:
df['ProductToRetire']=0
So my question is, It´s there anyway to itirate this in a simpler way?
Solution 1:[1]
You cannot use node-based functions in a browser environment, to do such a thing in a proper way you should build an HTTP/HTTPS API for your react application and make requests from react to your API.
You can go through by googling building a simple node server based on express, and output your python script results in maybe .json file which you'll read with node (which will be sent on request from your react application).
Hope my answer will help you a bit.
Solution 2:[2]
Short answer: No. But other Node-based functions can be invoked using Browserify.
Refer to this link: https://github.com/browserify/browserify/issues/1816
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | keinsell |
| Solution 2 | crjacinro |
