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
🌐
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]#
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
Thousands Separator in a Number Column of Data Editor
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 Styler, but this format results in erro when used in the Data Editor. More on discuss.streamlit.io
🌐 discuss.streamlit.io
0
0
June 14, 2023
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
🌐
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
🌐
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.
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.io.formats.style.Styler.format.html
pandas.io.formats.style.Styler.format — pandas 3.0.1 documentation
Styler.format(formatter=None, subset=None, na_rep=None, precision=None, decimal='.', thousands=None, escape=None, hyperlinks=None)[source]#
🌐
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…
Find elsewhere
🌐
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.
🌐
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:
🌐
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/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.

🌐
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...
🌐
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
🌐
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 :)

🌐
Linux find Examples
queirozf.com › entries › pandas-display-options-examples-and-reference
Pandas Display Options: Examples and Reference
August 22, 2023 - Use pandas.set_option('display.float_format', lambda x: '{:,.2f}' % x) to use comma separators and 2 decimal places · import pandas as pd pd.set_option('display.float_format', lambda x: '{:,.2f}'.format(x)) pd.DataFrame({ "num":[100000, 100,100,200.50], "str":["foo","bar","baz","quux"] }) BEFORE: default display options · AFTER: using commas as thousands separator and 2 decimal places ·
🌐
Iifx
iifx.dev › en › articles › 457660460
python - Pandas Integer Formatting: A Guide to Thousands Separators
Here's how you can do that using the Styler object, which is built into pandas for this exact purpose