Python Forum

Full Version: passing variable to function
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
show what you have tried so far
Can you not just send the slice?
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)
(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')