Leading and Trailing Spaces
Learn how to handle leading and trailing spaces using Python.
Leading and trailing spaces
When working with datasets, we may encounter leading or trailing spaces, which are spaces located before or after the first character of the dataset values. For example, a dataset with a CITY
column may contain leading spaces in front of the column values, such as " Lahore"
or " Seattle"
. These spaces may occur due to unintentional data entry by respondents, or they may be collected as part of the intended data by the data collection system. To prevent leading or trailing spaces, some data collection software may throw an error if the data contains these spaces and require the user to remove them before saving.
Get hands-on with 1400+ tech skills courses.