Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

pandas apply function on two columns

def stream_half(col1, col2):
    if col1 == 'desktop':
        return col2/2
    else:
        return int(col2)
        
df['clean'] = df.apply(lambda row: stream_half(row['device'], 
  row['streams']), axis = 1) 
 
PREVIOUS NEXT
Tagged: #pandas #apply #function #columns
ADD COMMENT
Topic
Name
9+6 =