If you don't know which are your file encoding, I think that the fastest approach is to open the file on a text editor, like Notepad++ to check how your file are encoding.

Then you go to the python documentation and look for the correct codec to use.

In your case , ANSI, the codec is 'mbcs', so your code will look like these

df_a = pd.read_csv('file.csv',sep=';',encoding='mbcs')
Answer from rflmorais on Stack Overflow
Author: pandas-dev
Discussions

python - ANSI Encoding for pandas on Google Colab? - Stack Overflow
So there's a file named as 'students_data.txt' which holds records in a tab separated form and file itself is encoded with ANSI coding. On my local Windows machine (ANSI is unconditionally supporte... More on stackoverflow.com
🌐 stackoverflow.com
June 6, 2020
python - Pandas- enabling ANSI encoding for read excel - Stack Overflow
I want to read an excel file and store it in dataframe. I am using pandas dataframe to read, but my excel workbook is encoded in ANSI. Newer pandas version has removed the encoding feature all toge... More on stackoverflow.com
🌐 stackoverflow.com
python - pandas to_csv: ascii can't encode character - Stack Overflow
I'm trying to read and write a dataframe to a pipe-delimited file. Some of the characters are non-Roman letters (`, ç, ñ, etc.). But it breaks when I try to write out the accents as ASCII. df = pd. More on stackoverflow.com
🌐 stackoverflow.com
python Convert Encoding:LookupError: unknown encoding: ansi - Stack Overflow
Because my cdv file is encoded as utf-8, opening it with Excel will cause distortion, and when I then convert it to the standard ANSI encoding, I get this error: code: import chardet def convertEn... More on stackoverflow.com
🌐 stackoverflow.com
🌐
GitHub
github.com › geopandas › geopandas › issues › 3016
BUG: ANSI and UTF-8 in same file · Issue #3016 · geopandas/geopandas
September 14, 2023 - I tried both engines. The error ocurred in both. I set the encoding to utf-8 for writing AND opening. Same error. I changed the format from geopckage to geojson (without setting the encoding) and opened in Notepad++ The letter Ä or ä was encoded ANSI in column name and utf-8 in the values.
Author: geopandas
🌐
py4u
py4u.org › blog › python-pandas-load-csv-ansi-format-as-utf-8
How to Load ANSI CSV Files as UTF-8 in Python Pandas: Fixing UnicodeDecodeError with Special Characters (ä, ö, ü, ß)
ANSI: A vague term often used to refer to region-specific encodings. On Windows, "ANSI" typically means Windows-1252 (a superset of Latin-1), which supports Western European languages but not global scripts.
🌐
Net Informations
net-informations.com › ds › err › uni.htm
UnicodeDecodeError while reading CSV file
On Windows, many editors assume the default ANSI encoding (CP1252 on US Windows, used in Western Europe and the Americas) instead of UTF-8 if there is no BOM (Byte Order Mark) character at the start of the file.
🌐
YouTube
youtube.com › the debug zone
Python pandas load csv ANSI Format as UTF-8 - YouTube
python: Python pandas load csv ANSI Format as UTF-8Thanks for taking the time to learn more. In this video I'll go through your question, provide various ans...
Published: August 7, 2024
Views: 11
🌐
CopyProgramming
copyprogramming.com › howto › how-to-set-encoding-as-ansi-using-python
Python: Setting the encoding to 'ANSI' in Python: A Guide
March 24, 2023 - ... To determine the encoding of your files, the quickest method would be to open them in a text editor such as Notepad++ and check their encoding. Next, you can refer to the Python documentation to find the appropriate codec for your needs. For ANSI, the codec used is 'mbcs', therefore your ...
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 74363534 › pandas-enabling-ansi-encoding-for-read-excel
python - Pandas- enabling ANSI encoding for read excel - Stack Overflow
@topsail: no. UTF-8 is not completely backward compatible: a code point above 127 is encoded with two bytes in UTF-8 and one byte in the wrongly called "ANSI encoding".
🌐
Dasboardai
dasboardai.com › blog › how-do-i-fix-an-unicode-error-in-python
How to fixed Encoding errors in pandas - DasBoardai.com
If you've encountered this error, you know how frustrating it can be. It typically occurs when the CSV file you're attempting to read is not encoded in UTF-8, but Pandas is trying to interpret it as such.
🌐
Finxter
blog.finxter.com › home › learn python blog › python csv to utf-8
Python CSV to UTF-8 - Be on the Right Side of Change
August 7, 2022 - import pandas as pd df = pd.read_csv('my_file.csv', encoding='ANSI') df.to_csv('my_file_utf8.csv', encoding='utf-8', index=False) The no-library approach to convert an ANSI-encoded CSV file to a UTF-8-encoded CSV file is to open the first file in the ANSI format and write its contents back in an UTF-8 file.
🌐
Saturn Cloud
saturncloud.io › blog › a-list-of-pandas-readcsv-encoding-options
A List of Pandas readcsv Encoding Options | Saturn Cloud Blog
May 1, 2026 - UTF-8 is the most widely used encoding format for text data. It supports all characters in the Unicode standard and is compatible with ASCII. To specify UTF-8 encoding in Pandas, use the encoding='utf-8' parameter.
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.Series.str.encode.html
pandas.Series.str.encode — pandas 3.0.5 documentation
Encode character string in the Series/Index using indicated encoding · Equivalent to str.encode()
🌐
Reddit
reddit.com › r/learnpython › can someone please fix this?!
r/learnpython on Reddit: Can someone PLEASE fix this?!
March 5, 2024 -

I have a Python Code that someone wrote for me to use, but they're now gone - and it's now broken - for who knows what reason, and I CANNOT seem to figure out this Python stuffs to save my damn life! Can SOMEONE please, please, PLEASE tell me - in real NON-CODING TYPE PERSON, step by step terms - how to fix this?? I included the code and then the error below.
(The code is suppose to be taking a bunch of data from spreadsheets and relabeling and combining it to one sheet for the entire month in question.)
Here is the coding:

import pandas as pd

import numpy as np

import glob

import pyautogui as pg

current_file = "2024 02"

location1 = fr"C:\Users\megan\Documents\Deposits\{current_file}\*.txt"

location2 = fr"C:\Users\megan\Documents\Deposits\{current_file}\retail orders.csv"

location3 = fr"C:\Users\megan\Documents\Deposits\{current_file}\wholesale orders.csv"

location4 = fr"C:\Users\megan\Documents\Sales Tax\zReports\{current_file} Sales Tax report - full.xlsx"

files = glob.glob(location1)

df_list = []

for f in files:

print(f)

txt = pd.read_csv(f)

df_list.append(txt)

ccfile = pd.concat(df_list)

ccoriginal = ccfile

ccfile["category"] = ccfile["Transaction Status"].map({

"Settled Successfully":"Settled Successfully",

"Credited":"Credited",

"Declined":"Other",

"General Error":"Other"}).fillna("Other")

ccfile = ccfile[ccfile["category"] != "Other"]

ccfile = ccfile[["Transaction ID","Transaction Status","Settlement Amount","Submit Date/Time","Authorization Code","Reference Transaction ID","Address Verification Status","Card Number","Customer First Name","Customer Last Name","Address","City","State","ZIP","Country","Ship-To First Name","Ship-To Last Name","Ship-To Address","Ship-To City","Ship-To State","Ship-To ZIP","Ship-To Country","Settlement Date/Time","Invoice Number","L2 - Freight","Email"]]

ccfile.rename(columns= {"Invoice Number":"Order Number"}, inplace=True)

ccfile["Order Number"] = ccfile["Order Number"].fillna(999999999).astype(np.int64)

ccfile.rename(columns= {"L2 - Freight":"Freight"}, inplace=True)

def catego(x):

if x["Transaction Status"] == "Credited":

return

if x["Order Number"] < 103000:

return "Wholesale"

if x["Order Number"] == 999999999:

return "Clinic"

return "Retail"

ccfile["type"] = ccfile.apply(lambda x: catego(x), axis=1)

def values(x):

if x["Transaction Status"] == "Credited":

return -1.0

return 1.0

ccfile["deposited"] = ccfile.apply(lambda x: values(x), axis=1) * ccfile["Settlement Amount"]

ccfile.sort_values(by="type", inplace=True)

# work with excel files from website downloads

# work with excel files from website downloads

columns_to_use = ["Order Number","Order Date","Order Status","First Name (Billing)","Last Name (Billing)","Company (Billing)","Address 1&2 (Billing)","City (Billing)","State Code (Billing)","Postcode (Billing)","Country Code (Billing)","Email (Billing)","Phone (Billing)","First Name (Shipping)","Last Name (Shipping)","Address 1&2 (Shipping)","City (Shipping)","State Code (Shipping)","Postcode (Shipping)","Country Code (Shipping)","Payment Method Title","Cart Discount Amount","Order Subtotal Amount","Shipping Method Title","Order Shipping Amount","Order Refund Amount","Order Total Amount","Order Total Tax Amount","SKU","Item #","Item Name","Quantity","Item Cost","Coupon Code","Discount Amount"]

retail_orders = pd.read_csv(location2)

retail_orders = retail_orders[columns_to_use]

wholesale_orders = pd.read_csv(location3)

wholesale_orders = wholesale_orders[columns_to_use]

details = pd.concat([retail_orders, wholesale_orders]).fillna(0.00)

details.rename(columns= {"Order Total Tax Amount":"SalesTax"}, inplace=True)

details.rename(columns= {"State Code (Billing)":"State - billling"}, inplace=True)

print(details)

# details["Item Cost"] = details["Item Cost"].str.replace(",","") # I don't know if needs to be done yet or not

#details["Item Cost"] = pd.to_numeric(details.Invoiced)

details["Category"] = details.SKU.map({"CT3-A-LA-2":"CT","CT3-A-ME-2":"CT","CT3-A-SM-2":"CT","CT3-A-XS-2":"CT","CT3-P-LA-1":"CT","CT3-P-ME-1":"CT",

"CT3-P-SM-1":"CT","CT3-P-XS-1":"CT","CT3-C-LA":"CT","CT3-C-ME":"CT","CT3-C-SM":"CT","CT3-C-XS":"CT","CT3-A":"CT","CT3-C":"CT","CT3-P":"CT",

"CT - Single - Replacement - XS":"CT","CT - Single - Replacement - S":"CT","CT - Single - Replacement - M":"CT","CT - Single - Replacement - L":"CT"}).fillna("OTC")

details["Row Total"] = details["Quantity"] * details["Item Cost"]

taxed = details[["Order Number","SalesTax","State - billling"]]

taxed = taxed.drop_duplicates(subset=["Order Number"])

ct = details.loc[(details["Category"] == "CT")]

otc = details.loc[(details["Category"]=="OTC")]

ct_sum = ct.groupby(["Order Number"])["Row Total"].sum()

ct_sum = ct_sum.reset_index()

ct_count = ct.groupby(["Order Number"])["Quantity"].sum()

ct_count = ct_count.reset_index()

otc_sum = otc.groupby(["Order Number"])["Row Total"].sum()

otc_sum = otc_sum.reset_index()

otc_count = otc.groupby(["Order Number"])["Quantity"].sum()

otc_count = otc_count.reset_index()

# combine CT and OTC columns together

count_merge = ct_count.merge(otc_count, on="Order Number", how="outer").fillna(0.00)

count_merge.rename(columns= {"Quantity_x":"CT Count"}, inplace = True)

count_merge.rename(columns = {"Quantity_y":"OTC Count"}, inplace = True)

merged = ct_sum.merge(otc_sum, on="Order Number", how="outer").fillna(0.00)

merged.rename(columns = {"Row Total_x":"CT"}, inplace = True)

merged.rename(columns = {"Row Total_y":"OTC"}, inplace = True)

merged = merged.merge(taxed, on="Order Number", how="outer").fillna(0.00)

merged = merged.merge(count_merge, on="Order Number", how="outer").fillna(0.00)

merged["Order Number"] = merged["Order Number"].astype(int)

# merge CT, OTC amounts with ccfile

complete = ccfile.merge(merged, on="Order Number", how="left")

complete = complete.sort_values(by=["Transaction Status","Order Number"])

complete["check"] = complete.apply(lambda x: x.deposited - x.CT - x.OTC - x.Freight - x.SalesTax, axis=1).round(2)

# save file

# save file

with pd.ExcelWriter(location4) as writer:

complete.to_excel(writer,sheet_name="cc Deposit split")

ccfile.to_excel(writer, sheet_name="cc deposit")

taxed.to_excel(writer, sheet_name="taxes detail")

retail_orders.to_excel(writer, sheet_name="Retail data")

wholesale_orders.to_excel(writer, sheet_name="wholesale data")

details.to_excel(writer, sheet_name="Full Details")

This is the error I get:

PS C:\Users\megan> & C:/Users/megan/AppData/Local/Microsoft/WindowsApps/python3.8.exe "c:/Users/megan/Documents/Python scripts/TEST - Monthly Sales Tax"

C:\Users\megan\Documents\Deposits\2024 02\dep 2024 02 01.txt

C:\Users\megan\Documents\Deposits\2024 02\dep 2024 02 02.txt

C:\Users\megan\Documents\Deposits\2024 02\dep 2024 02 03.txt

C:\Users\megan\Documents\Deposits\2024 02\dep 2024 02 04.txt

C:\Users\megan\Documents\Deposits\2024 02\dep 2024 02 05.txt

C:\Users\megan\Documents\Deposits\2024 02\dep 2024 02 06.txt

C:\Users\megan\Documents\Deposits\2024 02\dep 2024 02 07.txt

C:\Users\megan\Documents\Deposits\2024 02\dep 2024 02 08.txt

C:\Users\megan\Documents\Deposits\2024 02\dep 2024 02 09.txt

C:\Users\megan\Documents\Deposits\2024 02\dep 2024 02 10.txt

C:\Users\megan\Documents\Deposits\2024 02\dep 2024 02 11.txt

C:\Users\megan\Documents\Deposits\2024 02\dep 2024 02 12.txt

C:\Users\megan\Documents\Deposits\2024 02\dep 2024 02 13.txt

C:\Users\megan\Documents\Deposits\2024 02\dep 2024 02 14.txt

C:\Users\megan\Documents\Deposits\2024 02\dep 2024 02 15.txt

C:\Users\megan\Documents\Deposits\2024 02\dep 2024 02 16.txt

C:\Users\megan\Documents\Deposits\2024 02\dep 2024 02 17.txt

C:\Users\megan\Documents\Deposits\2024 02\dep 2024 02 18.txt

C:\Users\megan\Documents\Deposits\2024 02\dep 2024 02 19.txt

C:\Users\megan\Documents\Deposits\2024 02\dep 2024 02 20.txt

C:\Users\megan\Documents\Deposits\2024 02\dep 2024 02 21.txt

C:\Users\megan\Documents\Deposits\2024 02\dep 2024 02 22.txt

C:\Users\megan\Documents\Deposits\2024 02\dep 2024 02 23.txt

C:\Users\megan\Documents\Deposits\2024 02\dep 2024 02 24.txt

C:\Users\megan\Documents\Deposits\2024 02\dep 2024 02 25.txt

C:\Users\megan\Documents\Deposits\2024 02\dep 2024 02 26.txt

C:\Users\megan\Documents\Deposits\2024 02\dep 2024 02 27.txt

C:\Users\megan\Documents\Deposits\2024 02\dep 2024 02 28.txt

C:\Users\megan\Documents\Deposits\2024 02\dep 2024 02 29.txt

Traceback (most recent call last):

File "c:/Users/megan/Documents/Python scripts/TEST - Monthly Sales Tax", line 60, in <module>

retail_orders = pd.read_csv(location2)

File "C:\Users\megan\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pandas\io\parsers\readers.py", line 912, in read_csv

return _read(filepath_or_buffer, kwds)

File "C:\Users\megan\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pandas\io\parsers\readers.py", line 577, in _read

parser = TextFileReader(filepath_or_buffer, **kwds)

File "C:\Users\megan\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pandas\io\parsers\readers.py", line 1407, in __init__

self._engine = self._make_engine(f, self.engine)

File "C:\Users\megan\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pandas\io\parsers\readers.py", line 1679, in _make_engine

return mapping[engine](f, **self.options)

File "C:\Users\megan\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pandas\io\parsers\c_parser_wrapper.py", line 93, in __init__

self._reader = parsers.TextReader(src, **kwds)

File "pandas\_libs\parsers.pyx", line 550, in pandas._libs.parsers.TextReader.__cinit__

File "pandas\_libs\parsers.pyx", line 639, in pandas._libs.parsers.TextReader._get_header

File "pandas\_libs\parsers.pyx", line 850, in pandas._libs.parsers.TextReader._tokenize_rows

File "pandas\_libs\parsers.pyx", line 861, in pandas._libs.parsers.TextReader._check_tokenize_status

File "pandas\_libs\parsers.pyx", line 2021, in pandas._libs.parsers.raise_parser_error

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x92 in position 22209: invalid start byte

🌐
Asana
forum.asana.com › english forum › developers & api
Encoding when exporting in CSV - Developers & API - Asana Forum
October 14, 2022 - Hi ! I’m trying to run a script to format the CSV file into a good looking Excel via python. Sometimes when exporting, it exports the file with a UTF-8 encoding and sometimes in a ANSI encoding. That mess with my code. Does anyone have a solution to make it that it always exports in a UTF-8 ...
🌐
DEV Community
dev.to › _aadidev › 3-ways-to-handle-non-utf-8-characters-in-pandas-242
3 Ways to Handle non UTF-8 Characters in Pandas - DEV Community
January 20, 2022 - Pandas, by default, assumes utf-8 encoding every time you do pandas.read_csv, and it can feel like staring into a crystal ball trying to figure out the correct encoding.
🌐
Quantum Tunnel
jrogel.com › python-3-pandas-encoding-issues
Python 3, Pandas and Encoding Issues – Quantum Tunnel
August 1, 2022 - What happens when you don’t know what encoding was used to save the file? Well, you can ask, but it is very unlikely that the file generator know… What to do? Well there are some libraries that can be helpful. Install the chardet module as follows from the terminal ... import chardet import pandas as pd def find_encoding(fname): r_file = open(fname, 'rb').read() result = chardet.detect(r_file) charenc = result['encoding'] return charenc my_encoding = find_encoding('myfile.csv') df = pd.read_csv('myfile.csv', encoding=my_encoding)
🌐
Itecnote
itecnote.com › tecnote › python-pandas-load-csv-ansi-format-as-utf-8
Python pandas load csv ANSI Format as UTF-8
온라인 포커 추천 사이트 TOP10을 레이크백·보너스·입출금 기준으로 직접 비교했습니다. 최대 60% 레이크백부터 노디포짓 보너스까지, 2026 년 검증된 해외 포커 플랫폼만 정리했습니다.