Python Forum
passing variable to function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
passing variable to function
#1
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.
Reply
#2
show what you have tried so far
Reply
#3
Can you not just send the slice?
Reply
#4
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)
Reply
#5
(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')
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  passing php variable to python file jerald 1 270 Jul-07-2021, 11:46 AM
Last Post: Larz60+
  Passing flags to python script, through a function xbit 4 784 Apr-20-2021, 06:32 AM
Last Post: ndc85430
  Please explain uncommon way of declaring and using variable [function.variable] esphi 4 708 Nov-07-2020, 08:59 AM
Last Post: buran
  Passing argument from top-level function to embedded function JaneTan 2 716 Oct-15-2020, 03:50 PM
Last Post: deanhystad
  Spyder Quirk? global variable does not increment when function called in console rrace001 1 530 Sep-18-2020, 02:50 PM
Last Post: deanhystad
  [split] Creating a variable as a function DPaul 23 2,150 Sep-07-2020, 05:20 PM
Last Post: DPaul
  Creating a variable as a function JarredAwesome 4 1,200 Sep-06-2020, 05:08 AM
Last Post: buran
  Function will not return variable that I think is defined Oldman45 6 1,258 Aug-18-2020, 08:50 PM
Last Post: deanhystad
  Mathplotlib - passing reference to axs to function qmfoam 5 1,255 Aug-17-2020, 09:02 PM
Last Post: qmfoam
  Need help with for loop and variable value substitution in a function rsurathu 2 920 Jul-21-2020, 06:47 AM
Last Post: rsurathu

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020