Created
April 26, 2015 09:22
-
-
Save shahifaqeer/44d8ebc0696c93653b17 to your computer and use it in GitHub Desktop.
Apply a function to multiple columns in a pandas dataframe using the axis=1 to do row-wise application!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
df = pd.DataFrame({'ID':['1','2','3'], 'J1': [0,2,3], 'J2':[1,4,5]}) | |
print df | |
lst = ['a','b','c','d','e','f'] | |
df['J3'] = df.apply(lambda row:lst[row['J1']:row['J2']],axis=1) | |
print df |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment