How can I delete this number in my "Kecamatan" Columns
Asked
Active
Viewed 35 times
0
-
Did my answer help you? – Park Feb 21 '22 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?](https://meta.stackoverflow.com/q/285551/15497888) 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](https://stackoverflow.com/q/20109391/15497888). – Henry Ecker Mar 02 '22 at 04:05
1 Answers
1
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

Park
- 2,446
- 1
- 16
- 25