Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.8k views
in Technique[技术] by (71.8m points)

python - How to remove integer values from column with pandas

I have a dataframe with info on multiple countries. The data is not very clean and some of the country names have integer values in them. like this China2 or Ukraine18.

I want to remove the integer values from all entries in the Country column but am not able to find a robust way to do this. Any help is appreciated


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use Series.str.replace:

df['Country'] = df['Country'].str.replace('d+', '')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...