Answers for "take first two characters of string python from df column"

1

extract first letter of column python

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
Posted by: Guest on November-02-2020
0

pandas column string first n characters

df1['StateInitial'] = df1['State'].str[:2]
print(df1) 
Posted by: Guest on March-10-2020

Code answers related to "take first two characters of string python from df column"

Python Answers by Framework

Browse Popular Code Answers by Language