I have a column in a dataframe containing a sample of the following values:
     Cabin
0    A12
1    C27
2    D56
3    E87
4    G21
5    J64
I would like to create another column containing ONLY the first letter of that column:
     Cabin   New_Cabin
0    A12     A
1    C27     C
2    D56     D
3    E87     E
4    G21     G
5    J64     J
Here it is, young Pandas apprentice.
df['my_easy_column'] = df.mycol.str[0]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With