Strip / trim all strings of a dataframe

df_obj = df.select_dtypes(['object'])
print (df_obj)
0    a  
1    c  

df[df_obj.columns] = df_obj.apply(lambda x: x.str.strip())
print (df)

   0   1
0  a  10
1  c   5

如果是series

df[0] = df[0].str.strip()

 

Strip / trim all strings of a dataframe

posted @ 2019-01-25 15:57  andy_0212  阅读(310)  评论(0编辑  收藏  举报