You have to access the str attribute per http://pandas.pydata.org/pandas-docs/stable/text.html

df1['Avg_Annual'] = df1['Avg_Annual'].str.replace(',', '')
df1['Avg_Annual'] = df1['Avg_Annual'].str.replace('$', '')
df1['Avg_Annual'] = df1['Avg_Annual'].astype(int)

alternately;

df1['Avg_Annual'] = df1['Avg_Annual'].str.replace(',', '').str.replace('$', '').astype(int)

if you want to prioritize time spent typing over readability.

Answer from mechanical_meat on Stack Overflow
🌐
GitHub
github.com › pandas-dev › pandas › issues › 2594
Support parsing thousands separators in floating point data · Issue #2594 · pandas-dev/pandas
December 24, 2012 - It seems that the decimal format works ok for the decimal sign or for the thousands but not combined. Reopen the issue? Example import pandas as pd from StringIO import StringIO data = """A;B;C 0;0,11;0,11 1.000;1000,11;1.000,11 20.000;20000,22;20.000,22 300.000;300000,33;300.000,33 4.000.000;4000000,44;4.000.000,44 5.000.000.000;5000000000,55;5.000.000.000,55""" df = pd.read_csv(StringIO(data), sep=';', thousands='.', decimal =',') print df.dtypes print df Results in A int64 B float64 C object A B C 0 0 1.100000e-01 0,11 1 1000 1.000110e+03 1.000,11 2 20000 2.000022e+04 20.000,22 3 300000 3.000003e+05 300.000,33 4 4000000 4.000000e+06 4.000.000,44 5 5000000000 5.000000e+09 5.000.000.000,55
Author   wesm
Discussions

python - How to remove commas from ALL the column in pandas at once - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work More on stackoverflow.com
🌐 stackoverflow.com
python - How can I remove the thousand comma separator when converting data frame columns? - Stack Overflow
State,City,Population,Poverty_... ... import pandas as pd df = pd.read_csv("/path... /sample_data") ... I suspect the comma separator is causing this problem. How can I remove those from my dataset? ... Yes, when you read in the csv, use the thousands paramete... More on stackoverflow.com
🌐 stackoverflow.com
How do I remove commas from data frame column - Pandas

Pandas has a built in replace method for "object" columns.

df["column"] = df["column"].str.replace(",","").astype(float)

Alternatively check out the pandas.to_numeric() function- I think this should work.

df["column"] = pd.to_numeric(df["column"])

You can also pass arguments for error handling with the pd.to_numeric() function. See the pandas documentation on it.

More on reddit.com
🌐 r/learnpython
2
2
October 28, 2015
How to remove "." as thousand separator in data frame?
By default gsub uses regular expression matching (that’s a powerful technique and you should definitely learn the basics of it). And the regular expression . matches any character, so what you’re doing is replace every character in the entire input string with the empty string. To fix this, you can either escape the . character to match a literal .; this is done via \\ (the backslash is the escape character for the regular expression language, but also for strings in R in general ; that’s why you need to double it up: one backslash to escape the . in the regular expression, and a second backslash to stop R from treating your single backslash as a string escape). Alternatively, you can tell tell gsub to perform direct text matching instead of regular expression matching, by specifying the fixed = TRUE argument: testpos$Tested <- as.numeric(gsub(".", "", testpos$Tested, fixed = TRUE)) More on reddit.com
🌐 r/rstats
13
5
February 23, 2021
🌐
Pandas
pandas.pydata.org › docs › dev › reference › api › pandas.io.formats.style.Styler.format.html
pandas.io.formats.style.Styler.format — pandas documentation
Styler.format(formatter=None, subset=None, na_rep=None, precision=None, decimal='.', thousands=None, escape=None, hyperlinks=None)[source]#
🌐
Practical Business Python
pbpython.com › currency-cleanup.html
Cleaning Up Currency Data with Pandas - Practical Business Python
That’s why the numeric values get converted to NaN . The solution is to check if the value is a string, then try to clean it up. Otherwise, avoid calling string functions on a number.
🌐
Reddit
reddit.com › r/rstats › how to remove "." as thousand separator in data frame?
r/rstats on Reddit: How to remove "." as thousand separator in data frame?
February 23, 2021 -

I have some data where some of the columns have "." as a thousand separator.

I have named the data frame 'testpos'. I have already tried using the gsub-function, but it returns NA-values for every observation

testpos$Tested <- as.numeric(gsub(".","",testpos$Tested))

Does anyone have a better way to do this, or know what I do wrong?

Thanks in advance.

Find elsewhere
🌐
Mark Needham
markhneedham.com › blog › 2021 › 04 › 11 › pandas-format-dataframe-numbers-commas-decimals
Pandas - Format DataFrame numbers with commas and control decimal places | Mark Needham
April 11, 2021 - This works, but we’ve lost the LTLA Name column and the Population column isn’t formatted how we’d like. Instead of passing a single style to style.format, we can instead pass a dictionary of {"column: "style"}. So to style Population with a comma as thousands separator and PercentageVaccinated with two decimal places, we can do the following:
🌐
Streamlit
discuss.streamlit.io › using streamlit
Thousands Separator in a Number Column of Data Editor - Using Streamlit - Streamlit
June 14, 2023 - Summary How to show thousands separator in a Number Column inside the Data Editor component introduced in streamlit 1.23? I tried to set the number format to “%,.2f” as it is recognized by the defautl pandas DataFrame S…
🌐
IncludeHelp
includehelp.com › python › format-a-number-with-commas-to-separate-thousands-in-pandas.aspx
Python - Format a number with commas to separate thousands in pandas
DataFrames are 2-dimensional data structures in pandas. DataFrames consist of rows, columns, and data. Suppose, we have a large DataFrame with a column named X. This column has a field of large numbers (in thousands or lakhs). We need to format these numbers by putting commas in between the digits for proper data analysis. To format a number with commas to separate thousands, you can use pd.options.display method which contains a feature called float_format which will allow us to format these numbers in such a way that they can be separated with commas.
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.read_csv.html
pandas.read_csv — pandas 3.0.1 documentation - PyData |
True, False, and NA values, and thousands separators have defaults, but can be explicitly specified, too.
🌐
Reddit
reddit.com › r/learnpython › removing number comma seperators in csv file
r/learnpython on Reddit: Removing number comma seperators in csv file
November 22, 2020 -

Hey guys, I have a csv file with any number greater than 999 being listed as a string in the form “1,000”. including the quotes. I’m trying to get rid of these commas so I can turn them into an integer, however I’m unsure how to do it without touching the other commas used to seperate the values. Any suggestions? So far I have thought this out but it’s not quite right.

‘’’ import pandas as pd df = pd.read_csv(‘..., sep = “, “)

firstline = True

if firstline: firstline = False else: for line in df: if “,” in line[3]: #the column with the values line[3].replace(“,”, “ “)

‘’’

Sorry for the formatting I am on phone. Thanks for the help :)

🌐
Stack Overflow
stackoverflow.com › questions › 54941642 › string-with-space-as-thousand-separator-to-float-python-pandas-can-not-replace
string with space as thousand separator to float Python Pandas can not replace ' ' with '' - Stack Overflow
March 1, 2019 - I am trying to remove space as thousands separator from pandas series. print(newframe['ALV 0 %'].head()) newframe['ALV 0 %'] = newframe['ALV 0 %'].str.replace(',','.') newframe['ALV 0 %'] = newfra...
🌐
Reddit
reddit.com › r/learnpython › [pandas] how to specify thousand separator for int column?
r/learnpython on Reddit: [Pandas] How to specify thousand separator for int column?
August 31, 2018 -

/edit seems I found some outdated information online, read_excel() DOES support setting a thousands separator

dfa = pd.read_excel("file.xlsx", thousands=".")

Case closed

I have a column I read from Excel via read_excel("file.xlsx") with:

2.699 
2.507 
2.716 
3.229

Since I'm in the EU this are integers with values "2699, 2507, 2716, 3229" and the '.' is the thousand separator, not ','.

Panda uses the US standard so while converting it to int (there are trailing spaces so Pandas reads it as strings, then I strip them, then I convert to int) I get "2, 2, 2, 3".

read_csv() has the option to set the separator but read_excel() does not.

How can I change the thousand / comma separator to get the correct result?

🌐
Reddit
reddit.com › r/learnpython › pandas df: how to add thousand separators to a column?
r/learnpython on Reddit: Pandas df: How to add thousand separators to a column?
May 29, 2021 -

Two points here. I've 'pd.read_csv'ed a CSV file which has three columns.

I've used the following in order to extract the data and add headings to the columns (as currently the data is just naked)

Column 1 & 3 are text, and column 2 is a number.

How can I output the number with separators? EG 1,000,000 rather than 1000000

Also, what's the best way for formatting this dataframe to be included in an email body?

🌐
GitHub
github.com › pandas-dev › pandas › issues › 30045
Thousands separator for to_csv · Issue #30045 · pandas-dev/pandas
December 4, 2019 - Pandas exposes a thousands optional parameter to read_csv used to specify a custom thousands separator, so that 1,000 or 1_000 can be successfully parsed to a numeral in the resulting DataFrame. Un...
Author   ghisvail