1cols = df.select_dtypes(['object']).columns
2df[cols] = df[cols].apply(lambda x: x.str.strip())
3print (df)
4 A B C
50 A b NaN 3.0
61 NaN NaN 3.0
72 random NaN 4.0
83 any txt is possible 2 1 22.0
94 NaN 99.0
105 help NaN NaN
1df = df.applymap(lambda x: x.strip() if isinstance(x, str) else x)
2print (df)
3 A B C
40 A b 2 3.0
51 NaN 2 3.0
62 random 43 4.0
73 any txt is possible 2 1 22.0
84 23 99.0
95 help 23 NaN