-1

Im performing some operation within the dataframe and then splitting it into two dataframes. my problem is when i use the return function it combines both dataframes and return them as a tuple instead of two separate dataframes.

def block_dsgn(design,clmn='a',val=-1):
 
if design[clmn].eq(val).any():
    blck1 = pd.DataFrame(design[design[clmn]==val])
    blck2 = pd.DataFrame(design[design[clmn]!= val])
return blck1, blck2
    

if ~ design[clmn].eq(val).any():
    return 'check block factor value...val parameter'
hghebrem
  • 5
  • 2
  • 1
    Does this answer your question? [Alternatives for returning multiple values from a Python function](https://stackoverflow.com/questions/354883/alternatives-for-returning-multiple-values-from-a-python-function) – wovano Oct 08 '22 at 08:50
  • See also: [Is it pythonic for a function to return multiple values?](https://stackoverflow.com/questions/61605/is-it-pythonic-for-a-function-to-return-multiple-values) – wovano Oct 08 '22 at 08:50

1 Answers1

0

Is it what you want?

def block_dsgn(design,clmn='a',val=-1):
 
  if design[clmn].eq(val).any():
      blck1 = pd.DataFrame(design[design[clmn]==val])
      blck2 = pd.DataFrame(design[design[clmn]!= val])
  return blck1, blck2

a, b = block_dsgn(...)

a and b are two separate dataframes

zerg468
  • 104
  • 3
  • in a way. i want the function to generate that, instead of me having to split it outside of the function. – hghebrem Oct 06 '22 at 20:49