Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

multiple args for pandas apply

df["col_added"] = df.apply(lambda x: add_a_b(x["col_1"], x["col_2"]), axis = 1)
Comment

pandas apply with multiple arguments

def some_func(row, var1):
    return str(row['A']) + '-' + str(row['B']) + '-' + var1

df['C'] = df.apply(some_func, var1='DOG', axis=1)
df

       A    B            C
0    foo    x    foo-x-DOG
1    bar    y    bar-y-DOG
Comment

pandas dataframe apply function with multiple arguments

def some_func(row, var1):
    return '{0}-{1}-{2}'.format(row['A'], row['B'], var1)

df['C'] = df.apply(some_func(row, var1='DOG'), axis=1)

df


       A    B            C
0    foo    x    foo-x-DOG
1    bar    y    bar-y-DOG
Comment

PREVIOUS NEXT
Code Example
Python :: django form widget 
Python :: django dumpdata 
Python :: tkinter window background color 
Python :: python check if number 
Python :: binary string to hex python 
Python :: pandas strips spaces in dataframe 
Python :: TinyDB 
Python :: python dont exit script after print 
Python :: two loop type python 
Python :: decrease hours in datetime python 
Python :: notebook seaborn display size pairplot 
Python :: python tkinter frame title 
Python :: python unit testing machine learning 
Python :: python replace first 
Python :: install hydra python 
Python :: django template for range 
Python :: read excel file spyder 
Python :: django making a custom 403 page 
Python :: python read folder 
Python :: python make a list of odd numbers 
Python :: del keyword in python 
Python :: python loop x times 
Python :: plot rows of dataframe pandas 
Python :: Creating a list with list comprehensions 
Python :: pygame how to get surface lenght 
Python :: python json open file 
Python :: how to create a label in tkinter 
Python :: plt change grid color 
Python :: simple http server python 
Python :: pandas iloc select certain columns 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =