Get The First & Last N Characters

Python
Data Preprocessing

 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)])
1 Upvote
Tags: String
Did you find this snippet useful?

Sign up to bookmark this in your snippet library

Normalize Windowed Time Series
Python
Data Preprocessing

Scaler | Normalize | Scale | Min-max

4
Pivoting Pandas Dataframes
Python
Data Preprocessing

Pandas

3