close

How to remove commas from ALL the column in pandas at once

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to remove commas from ALL the column in pandas at once in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to remove commas from ALL the column in pandas at once?

  1. How to remove commas from ALL the column in pandas at once?

    Numeric columns have no ,, so converting to strings is not necessary, only use DataFrame.replace with regex=True for substrings replacement:

  2. remove commas from ALL the column in pandas at once

    Numeric columns have no ,, so converting to strings is not necessary, only use DataFrame.replace with regex=True for substrings replacement:

Method 1

Numeric columns have no ,, so converting to strings is not necessary, only use DataFrame.replace with regex=True for substrings replacement:

df = df.replace(',','', regex=True)

Or:

df.replace(',','', regex=True, inplace=True)

And last convert strings columns to numeric, thank you @anki_91:

c = df.select_dtypes(object).columns
df[c] = df[c].apply(pd.to_numeric,errors='coerce')

Method 2

Well, you can simplely do:

df = df.apply(lambda x: x.str.replace(',', ''))

Hope it helps!

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read