Skip to content
Advertisement

storing result from function directly into DataFrame with return

I’m new to programming and python,

I’m trying to create a function to iterate over a dataframe and directly store results from the function to dataframe, so far here is what I’ve done:

JavaScript

after running it I’m able to get the NumPy array from p and store it to a variable then transform it into dataframe, but that’s only work in the first datapoint since the return exits the function after it satisfies the first condition. What alternative I can do so Im able to get all the results from the function as a NumPy array or directly save it to dataframe

thank you

Advertisement

Answer

Here’s what you need –

My data is made up, so the values might not be representative of the problem you are trying to solve, but it will work with the dataframe you have given the columns are located at the same index as assumed in solution below.

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement