Reputation: 17
I want to remove whitespace after all data in the excel table using panda in Jupiter notebook. foreg:
| A header | Another header |
| -------- | -------------- |
| First**whitespace** | row |
| Second | row**whitespace** |
output:
| A header | Another header |
| -------- | -------------- |
| First | row |
| Second | row |
Upvotes: 1
Views: 32
Reputation: 862681
If all columns are strings use rstrip
in DataFrame.applymap
:
df = df.applymap(lambda x: x.rstrip())
Or Series.str.rstrip
for columns in DataFrame.apply
:
df = df.apply(lambda x: x.str.rstrip())
If possible some non strings (non object) columns is possible filter columns names:
cols = df.select_dtypes(object).columns
df[cols] = df[cols].apply(lambda x: x.str.rstrip())
Upvotes: 1