apply strip() a column in pandas 1

apply strip() a column in pandas

df[0] = df[0].str.strip()

Here is what the above code is Doing:
1. We’re using the read_csv function to read in the data.
2. We’re using the header=None argument to tell the function that the data doesn’t have a header row.
3. We’re using the names argument to give the columns descriptive names.
4. We’re using the dtype argument to specify that the first column should be read in as a string.
5. We’re using the str.strip() method to remove the whitespace from the beginning and end of the string.

Similar Posts