How to change values in certain columns according to certain rule in pandas dataframe
You may need to use isnull():

df['col2'] = df['col2'].apply(lambda x: str(x)[0] if not pd.isnull(x) else x)
Suppose I have a pandas dataframe looks like this:

    col1    col2
0   A       A60
1   B       B23
2   C       NaN

The data from is read from a csv file. Suppose I want to change each non-missing value of 'col2' to its prefix (i.e. 'A' or 'B'). How could I do this without writing a for loop?
The expected output is 

    col1    col2
0   A       A
1   B       B
2   C       NaN