Created
January 15, 2026 07:17
-
-
Save yeiichi/2bd7ef5347742b806fd98faaf9bf9c93 to your computer and use it in GitHub Desktop.
Strip leading and trailing whitespace from DataFrame string cells, leaving other types unchanged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def strip_df(df): | |
| """Strip leading and trailing whitespace from DataFrame string cells, leaving other types unchanged.""" | |
| return df.map(lambda s: s.strip() if isinstance(s, str) else s) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment