pandas column string first n characters
df1['StateInitial'] = df1['State'].str[:2]
print(df1)
pandas column string first n characters
df1['StateInitial'] = df1['State'].str[:2]
print(df1)
Get first letter of a string from column
In [29]:
df['new_col'] = df['First'].astype(str).str[0]
df
Out[29]:
First Second new_col
0 123 234 1
1 22 4353 2
2 32 355 3
3 453 453 4
4 45 345 4
5 453 453 4
6 56 56 5
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us