take substring of every element in dataframe 1

take substring of every element in dataframe

df['col'] = df['col'].str[:9]

Here is what the above code is Doing:
1. We’re using the str accessor to access the string methods on the column.
2. We’re using the str[:9] method to slice the first 9 characters of the string.

Similar Posts