-1

I want to remove non-numeric data from numerical data. My dataframe has 720000 rows and 11 columns and there is one column which has this type of data

id1080784

id0889885

id0857912

id3744273

id0232939 .....

I want to remove the 'id' word from all of these rows. Please share your suggestions in Python only.

Thanks!

  • We are not seeing the codes so I think I can only mention about the methods that you can do. You can use the `replace` method of the `str` data type like `string.replace("id", "")` or you can slice the string using the indexes of the string like `string[2:]`. Then you can convert the data type of the value from `str` to `int`. – dildeolupbiten Apr 20 '20 at 21:05
  • Is input from a CSV file? What output do you want - a pandas dataframe? What have you tried? Try [`str.slice`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.str.slice.html), [`str.replace`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.str.replace.html) or [`str.extract`](https://stackoverflow.com/questions/37683558/pandas-extract-number-from-string), and check the [guide on working with text data in pandas](https://pandas.pydata.org/pandas-docs/stable/user_guide/text.html) – Stuart Apr 20 '20 at 21:24

1 Answers1

-1

One method is that you can use str replace. And just replace 'id' with nothing.

import pandas as pd
col = pd.DataFrame(['id1080784', 'id0889885', 'id0857912', 'id3744273'])
col[0] = col[0].str.replace('id','')
Meathusk
  • 34
  • 4