Search code examples
pythonreplaceattributeerror

How to replace "," with ""? How can I delete the comma in my values?


I mean I have a column named num_students.

datatype of it is object and for example its written as 2,435

I want to get it as 2435 as object

What im trying to do is:

  • timesData is the dataframe, num_students is column

timesData.num_students = [ each.replace(",","") for each in timesData.num_students]

I get error : AttributeError: 'float' object has no attribute 'replace'


Solution

  • One way to do it using str.replace,

    timesData['num_students'] = timesData['num_students'].str.replace(',', '')
    

    str.replace(',', '') replaces the comma with nothing