Python Forum
passing variable to function - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: passing variable to function (/thread-29157.html)



passing variable to function - Rejoice - Aug-20-2020

am trying to pass two columns from two different dataframes, is there any way i can do it. I tried .apply however it will help me to pass two columns of same dataframe.


RE: passing variable to function - Larz60+ - Aug-20-2020

show what you have tried so far


RE: passing variable to function - jefsummers - Aug-20-2020

Can you not just send the slice?


RE: passing variable to function - Rejoice - Aug-21-2020

def R1(df):
    if df['OPEN']>df['CLOSE']:
        return "BEARISH"
    elif df['OPEN']<df['CLOSE']:
        return "BULLISH"
    
    
day1['type analysis'] = df.apply(R1,axis=1)
the above code is what i trying to achieve.

when the columns ['OPEN'] & ['CLOSE'] are in the same dataframe (df) i could pass it to the function as a whole dataframe and inside the function i can take necessary column and do the calculations. I was trying to figure out if there is a means to pass the only desired columns from two different dataframes into the function.

df.apply helps me to pass the whole dataframe, likewise can i pass two columns of two different dataframe (df1 & df2) to the function, and store the returned value to another dataframe (df3)


RE: passing variable to function - Pleiades - Sep-11-2020

(Aug-20-2020, 04:48 PM)Rejoice Wrote: am trying to pass two columns from two different dataframes, is there any way i can do it. I tried .apply however it will help me to pass two columns of same dataframe.

I presume you are working on some sort of stock market analysis, regarding if the market will be a good trading day or bad, (i.e. forecasting bears and bulls daily) through a bearish or bullish record. The only way I did it manually without a direct feed from the market was to put in a record of the Dow.

The "sum" was useful in the list.


while True:
	df1 = int(float(input("Enter the opening of DOW Jones markets: ")))
	df2 = int(float(input("Enter the closing of DOW Jones markets: ")))

	OPEN = [0,0,df1]
	CLOSE = [0,0,df2]

	if (sum(OPEN))>(sum(CLOSE)):
		
		print((sum(OPEN))-(sum(CLOSE)), 'OPENING')
		
		print(('BEARISH'))
	elif (sum(OPEN))<(sum(CLOSE)):
		print((sum(OPEN))+(sum(CLOSE)), 'CLOSING')
		print(('BULLISH'))
	else:
		
		print('Dow Jones Unchanged')