pandas strip all whitespace code example
Example 1: Python function remove all whitespace from all character columns in dataframe
df.columns = df.columns.str.replace(' ', '')
Example 2: python remove whitespace from start of string
' hello world! '.strip()
'hello world!'
' hello world! '.lstrip()
'hello world! '
' hello world! '.rstrip()
' hello world!'