Q:

str.strip() removes number?

I got the following DataFrame:
    DATE       STG #TIME    HRD SZ  AREA BEAU   PSD EFFORT TYPE NORTHING EASTING SEASON BOAT ASSOC. P/S
0   2016-04-06  1   1025    12  W LANTAU    2   58  ON  HKCRP   813713  802792  SPRING  NONE    S
1   2016-04-06  2   1113    3   W LANTAU    4   27  ON  HKCRP   806173  802043  SPRING  NONE    S
2   2016-04-06  3   1345    2   SW LANTAU   2   ND  OFF HKCRP   805606  803300  SPRING  NONE    NaN

when I do 
#remove space in content
df_obj = sighting.select_dtypes(['object'])
df_obj
sighting[df_obj.columns] = df_obj.apply(lambda x: x.str.strip())

It removes the value in PSD column and made them as NaN. Why is that? and How can I fix it? Thank you!

A:

My bet is that the object column PSD has mixed types of string and ints:
In [11]: df_obj.PSD.values
Out[11]: array([58, 27, 'ND'], dtype=object)

In [12]: df_obj.apply(lambda x: x.str.strip())
Out[12]:
         DATE  SZ    AREA  PSD EFFORT   TYPE  SEASON  BOAT ASSOC.P/S
0  2016-04-06   W  LANTAU  NaN     ON  HKCRP  SPRING  NONE         S
1  2016-04-06   W  LANTAU  NaN     ON  HKCRP  SPRING  NONE         S
2  2016-04-06  SW  LANTAU   ND    OFF  HKCRP  SPRING  NONE       NaN

You can work around this by forcing all the object columns to string:
In [13]: df_obj.astype("str").apply(lambda x: x.str.strip())
Out[13]:
         DATE  SZ    AREA PSD EFFORT   TYPE  SEASON  BOAT ASSOC.P/S
0  2016-04-06   W  LANTAU  58     ON  HKCRP  SPRING  NONE         S
1  2016-04-06   W  LANTAU  27     ON  HKCRP  SPRING  NONE         S
2  2016-04-06  SW  LANTAU  ND    OFF  HKCRP  SPRING  NONE       nan

Note: You can see this isn't perfect as the NaN was converted to 'nan'... you could workaround this with .where though I suspect there is a better way:
In [21]: df_obj.where(df_obj.isnull(), df_obj.astype("str")).apply(lambda x: x.str.strip())
Out[21]:
         DATE  SZ    AREA PSD EFFORT   TYPE  SEASON  BOAT ASSOC.P/S
0  2016-04-06   W  LANTAU  58     ON  HKCRP  SPRING  NONE         S
1  2016-04-06   W  LANTAU  27     ON  HKCRP  SPRING  NONE         S
2  2016-04-06  SW  LANTAU  ND    OFF  HKCRP  SPRING  NONE       NaN

