Stumbled onto this question while looking for a quick and minimalistic snippet I could use. Had to assemble one myself from posts above. Maybe someone will find it useful:
data_frame_trimmed = data_frame.apply(lambda x: x.str.strip() if x.dtype == "object" else x)
More Related Contents:
- How to drop rows of Pandas DataFrame whose value in a certain column is NaN
- How to make separator in pandas read_csv more flexible wrt whitespace, for irregular separators?
- Why isn’t my Pandas ‘apply’ function referencing multiple columns working? [closed]
- Convert the string 2.90K to 2900 or 5.2M to 5200000 in pandas dataframe
- Conditionally fill column values based on another columns value in pandas
- Drop rows containing empty cells from a pandas DataFrame
- How to form tuple column from two columns in Pandas
- Remove duplicate rows from Pandas dataframe where only some columns have the same value
- Normalize columns of a dataframe
- Pandas selecting by label sometimes return Series, sometimes returns DataFrame
- How to switch columns rows in a pandas dataframe
- Quickest way to make a get_dummies type dataframe from a column with a multiple of strings
- Pandas groupby.size vs series.value_counts vs collections.Counter with multiple series
- “unstack” a pandas column containing lists into multiple rows [duplicate]
- How to check whether a pandas DataFrame is empty?
- Python pandas Filtering out nan from a data selection of a column of strings
- Remove name, dtype from pandas output of dataframe or series
- Copy pandas dataframe to excel using openpyxl
- How to drop unique rows in a pandas dataframe?
- pandas – find first occurrence
- How to convert a dataframe to a dictionary
- Read CSV into a dataFrame with varying row lengths using Pandas
- Filling missing values using forward and backward fill in pandas dataframe (ffill and bfill)
- Truncate `TimeStamp` column to hour precision in pandas `DataFrame`
- Remove row with null value from pandas data frame
- How to use str.contains() with multiple expressions in pandas dataframes
- Check if certain value is contained in a dataframe column in pandas [duplicate]
- UnicodeDecodeError when reading CSV file in Pandas
- How to return a csv file/Pandas DataFrame in JSON format using FastAPI?
- How to get number of groups in a groupby object in pandas?