Python function remove all whitespace from all character columns in dataframe
df.columns = df.columns.str.replace(' ', '')
Python function remove all whitespace from all character columns in dataframe
df.columns = df.columns.str.replace(' ', '')
remove leading and lagging spaces dataframe python
cols = df.select_dtypes(['object']).columns
df[cols] = df[cols].apply(lambda x: x.str.strip())
print (df)
A B C
0 A b NaN 3.0
1 NaN NaN 3.0
2 random NaN 4.0
3 any txt is possible 2 1 22.0
4 NaN 99.0
5 help NaN NaN
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us