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

原文地址:https://www.cnblogs.com/andy-0212/p/10320091.html