I have to achieve the below scenario, I am very new to Python I have a method which takes a data frame and split that data frame into two data frames based on some conditions. Ex:
def splitdf(df:DataFrame) {
return [df1, df2]
retuns two data frames // how can we return two data frames if it is list then another method which takes one of these two data frames as an input is failing because its a list.
}
df1, df2 = splitdf(dftest) // this assignment is failing
need to pass these df1 and df2 as a data frame to some other methods like below
calculate(df1)
calculate(df2)
since above line are failing, I am doing below
df=splitdf(dftest)
calculate(df[0])
calculate(df[1])
// the problem here is calculate method is failing because it is expecting parameter as data frame but if I am passing like df[0] it is taking it as a list only. I need to send two data frames to calculate() method separately after splitting the data in splitdf().
Example:
data = {'id':[1,2,3,4],
'Name':['Tom', 'Jack', 'Steve', 'Ricky'],
'Age':[28,34,29,42],
'Addr':['addr1,'addr2','addr3','addr4'],
'mobile':['mob1','mob2','mob3','mob4'],
'sex':['M','M','M','M']
}
dftest = pd.DataFrame(data)
suppose above data frame splitted into by calling splitdf(dftest)
def splitdf(dftest) {
//some code to split dftest
return [df1, df2] //method has to return two data frames after
splitting. after splitting consider df1 with
columns id, name, age, sex. df2 with columns
id, addr, mobile.
}
dfs = splitdf(dftest)
Now want to pass these two data frames dfs[0], df[1] to calculate() method (which accepts DataFrame as parameter) to do processing further.
But if we are passing like this calculate(dfs[0]) //dfs[0] is going as list only not dataframe. I want to pass as DataFrame.