How can I delete this number in my "Kecamatan" Columns
-
Did my answer help you?Park– Park2022-02-21 14:38:57 +00:00Commented Feb 21, 2022 at 14:38
-
Please do not link or embed external images of source code or data. Images make it difficult to efficiently assist you as they cannot be copied and offer poor usability as they cannot be searched. See: Why not upload images of code/errors when asking a question? If you need assistance formatting a small sample of your DataFrame as a copyable piece of code for SO see How to make good reproducible pandas examples.Henry Ecker– Henry Ecker ♦2022-03-02 04:05:11 +00:00Commented Mar 2, 2022 at 4:05
Add a comment
|
1 Answer
You can replace the leading digits and dot using regular expression, as follows:
import pandas as pd
df = pd.DataFrame({
'Kecamatan': ['010. Donomulyo', '020. Kalipare', '030. Pagak', '040. Bankur']
})
df['Kecamatan'] = df['Kecamatan'].str.replace(r'\A[0-9. ]+', '', regex=True)
print(df)
>>>df
Kecamatan
0 Donomulyo
1 Kalipare
2 Pagak
3 Bankur
