I\'m reading a CSV file into a DataFrame. I need to strip whitespace from all the stringlike cells, leaving the other cells unchanged in Python 2.7.
Here is what I\
You could use pandas' Series.str.strip() method to do this quickly for each string-like column:
Series.str.strip()
>>> data = pd.DataFrame({'values': [' ABC ', ' DEF', ' GHI ']}) >>> data values 0 ABC 1 DEF 2 GHI >>> data['values'].str.strip() 0 ABC 1 DEF 2 GHI Name: values, dtype: object