I have a dataframe column of first and last names. I want to extract the initials from the names as another column in my dataframe. For the following dataframe:
Name
0 'Brad Pitt'
1 'Bill Gates'
2 'Elon Musk'
I have came up with a solution:
df['initials'] = [df['Name'][i].split()[0][0] + df['Name'][i].split()[1][0] for i in range(len(df))]
However, for a name such as 'John David Smith', this does not work, as I want to have the first letter of each word in a name. Moreover, since my dataframe is quite large, I would like to know if there is a 'vectorized' solution (without for loops).
Thank you in advance.