0

I am converting this Excel formula into Pandas and Python.

=IF(ISBLANK('Raw Data'!$A3),"",IF(OR(ISERROR((('Raw Data'!BY3+'Raw Data'!BZ3)*'Raw Data'!BX3*12)),'Raw Data'!BY3=0),'Raw Data'!CN3,(('Raw Data'!BY3+'Raw Data'!BZ3)*'Raw Data'!BX3*12)))

This returns value into a column in a dataframe.

I have converted raw_data into a dataframe. I have written my logic in Python in a defined function.

How should I apply that function to the raw dataframe to the multiple column at once? i am unable to do-

df['output column name']=rawdf['input_colm name'].apply(function_name, axis=0)

Since I have to go vertically down the column one by one, I am using axis=0.

Edit

The Excel code is written into Python logic for more clarity, and the number used with BX/BY/BZ i.e. 3 is just the indication that this formula is for one cell in a column and so as the values in the column goes down the values corresponding to the BX/BY/BZ -3 changes to BX4,BX5,BX6.../BY4,BY5,BY6 and so on.

Since in this I have to look at data vertically so I am using axis=0, as I need all rows values to be executed in a column .

The main issue is that how should i use "apply" here with so many different columns. Do I need to end columns as arguments too?

The logic is-

def output_column_name():

    for i in range(0,nloans):

        if ((raw_df['BY'][i]==0) or (isinstance((raw_df['BY'][i] + raw_df['BZ'][i] ) * raw_df['BX'][i]*12,float)==False)):

            return raw_df['CN'][i]
else:
            return (raw_df['BY'][i] + raw_df['BZ'][i] ) * raw_df['BX'][i]*12

df['OUTPUT COLUMN NAME']=raw_df.apply( output_column_name,axis=0)

I have also converted raw_df and df as numpyarray

halfer
  • 19,824
  • 17
  • 99
  • 186
bewilderd
  • 11
  • 3
  • 3
    Hello and welcome. This question needs quite a bit more formatting before anyone can try to make sense out of it. Also, please do not use all capitals in your title, it's considered equivalent of yelling at people and impolite. – Ondrej K. Jul 19 '18 at 21:18
  • Please [review the edit history](https://stackoverflow.com/posts/51431840/revisions) to see how much volunteer editing was required to make this question readable, and consider how you could ask questions in the future with these improvements already made. We simply do not have enough willing editors to carry out this sort of repair for everybody. – halfer Jul 20 '18 at 06:49
  • Since,this is my first question I was unaware of the facts, my sincerest appologies. – bewilderd Jul 20 '18 at 16:55

0 Answers0