Get The First & Last N Characters

Python

 1|  # get the first two characters of each string in a DataFrame column
 2|  df['start'] = df['Name'].apply(lambda x: x[0:2])
 3|  
 4|  # get the last two characters of each string in a DataFrame column
 5|  df['end'] = df['Name'].apply(lambda x: x[-2:len(x)])
Did you find this snippet useful?

Sign up for free to to add this to your code library