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