To strip unwanted characters from a pandas dataframe column, you can use the str.strip()
method. This method removes the leading and trailing whitespaces or any other specified characters from each element in the given series.
Here is an example of how to use str.strip()
to remove whitespaces from a specific column of a pandas dataframe:
main.py252 chars11 lines
This code will output the following:
main.py40 chars5 lines
As you can see, the leading and trailing whitespaces from each element in the 'col_1' column have been removed.
gistlibby LogSnag