You have unicode values in your DataFrame. Files store bytes, which means all unicode have to be encoded into bytes before they can be stored in a file. You have to specify an encoding, such as utf-8. For example,

df.to_csv('path', header=True, index=False, encoding='utf-8')

If you don't specify an encoding, then the encoding used by df.to_csv defaults to ascii in Python2, or utf-8 in Python3.

Answer from unutbu on Stack Overflow
🌐
GitHub
github.com › pandas-dev › pandas › issues › 10813
to_csv with lists of strings and unicode encoding produces wrong output · Issue #10813 · pandas-dev/pandas
August 13, 2015 - If I have a dataframe with cells containing lists of strings (or unicode strings), then these lists are broken when I use to_csv() with the encoding parameter set. The error does not occur if the encoding is not set. Here is an example (...
Author: pandas-dev
Discussions

Suppress UnicodeEncodeError when executing to_csv method
Code Sample, a copy-pastable example if possible # error pattern import pandas as pd unicode_data = [["key", "\u070a"]] df = pd.DataFrame(unicode_data) df.to_csv("./test.csv", encoding="cp932") # U... More on github.com
🌐 github.com
7
August 5, 2019
python - Pandas to_csv correct way to handle UnicodeEncodeError - Stack Overflow
I'm processing a file csv file with pandas, so, I open it: df = pd.read_csv(my_file, low_memory=False) I'm applying some sanitizing functions, changing some strings to numbers, and then when I wan... More on stackoverflow.com
🌐 stackoverflow.com
python - Pandas df.to_csv("file.csv" encode="utf-8") still gives trash characters for minus sign - Stack Overflow
I've read something about a Python 2 limitation with respect to Pandas' to_csv( ... etc ...). Have I hit it? I'm on Python 2.7.3 This turns out trash characters for ≥ and - when they appear in st... More on stackoverflow.com
🌐 stackoverflow.com
to_csv failing with encoding='utf-16'
In first place, big thank you for supporting pandas, my life is easier and fun with pandas in the toolkit. In previous version 0.22 we were able to do to_csv with encoding='utf-16' to handle Japanese, Chinese among other content properly. Need the utf-16 encoding for next steps like upload ... More on github.com
🌐 github.com
4
May 18, 2018
People also ask

Why does utf-8 encoding fail for special characters in Pandas?
A: Python 2.7 has limited Unicode handling, and certain characters may not be supported. Excel’s default CSV reader may also misinterpret UTF-8 files without a BOM.
🌐
sqlpey.com
sqlpey.com › python › fix-pandas-to_csv-encoding-issues-with-special-characters
Solved: How to Fix Pandas to_csv Encoding Issues with Special ...
Can I use utf-8 encoding with Python 3 to resolve the issue?
A: Yes, Python 3 handles UTF-8 more effectively. However, for compatibility with Excel, consider using utf-8-sig or utf-16.
🌐
sqlpey.com
sqlpey.com › python › fix-pandas-to_csv-encoding-issues-with-special-characters
Solved: How to Fix Pandas to_csv Encoding Issues with Special ...
How can I verify the encoding of my CSV file?
A: Use a text editor or tools like file command (Linux/Mac) or Notepad++ to check the encoding of the file.
🌐
sqlpey.com
sqlpey.com › python › fix-pandas-to_csv-encoding-issues-with-special-characters
Solved: How to Fix Pandas to_csv Encoding Issues with Special ...
🌐
Reddit
reddit.com › r/learnpython › pandas dataframe.to_csv() struggling with encoding
r/learnpython on Reddit: Pandas DataFrame.to_csv() struggling with encoding
January 14, 2021 -

Heya,

I got a DataFrame filled with strings in the first column and the rest consisting of integers (except for the headers).

Now when I export this dataframe to a csv file, and the strings contain German Umlauts (ä,ö,ü or something like ß), the exported csv file has weird looking strings at these indices.

Like "für" became "für".

As far as I know the default encoding for to_csv() is utf-8, which means it should work fine? But I also tried the parameter encoding='utf-8', same results.

What am I doing wrong here?

🌐
Varunpramanik
varunpramanik.com › chronicles › 2019 › 12 › 12 › pandas-to_csv-encoding-error-solution
Pandas to_csv Encoding Error Solution – Chronicles by Varun Pramanik
December 12, 2019 - new_df = original_df.applymap(lambda x: str(x).encode("utf-8", errors="ignore").decode("utf-8", errors="ignore"))
🌐
Sentry
sentry.io › sentry answers › python › write a python pandas dataframe to a csv file
Write DataFrame to CSV in Python Pandas With to_csv | Sentry
July 3, 2026 - index=False: this will prevent the DataFrame’s row labels from being included in the CSV file. encoding="utf-8": this ensures that the file is saved with UTF-8 encoding, preserving the Unicode character in “André.”
🌐
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 - To specify Latin-2 encoding in ... pd.read_csv('file.csv', encoding='iso-8859-2') UTF-16LE and UTF-16BE are encoding formats for Unicode text data that use 16 bits to represent each character....
🌐
GitHub
github.com › pandas-dev › pandas › issues › 27750
Suppress UnicodeEncodeError when executing to_csv method · Issue #27750 · pandas-dev/pandas
August 5, 2019 - # good pattern import pandas as pd unicode_data = [["key", "\u070a"]] df = pd.DataFrame(unicode_data) df.to_csv("./test.csv", encoding="cp932", ignore_error=True)
Author: pandas-dev
Find elsewhere
🌐
sqlpey
sqlpey.com › python › fix-pandas-to_csv-encoding-issues-with-special-characters
Solved: How to Fix Pandas to_csv Encoding Issues with Special Characters
November 17, 2024 - Manually Specify Encoding in Excel: When importing the CSV file, manually set the encoding to match your choice, such as UTF-8 or UTF-16. Learn more about Pandas to_csv() documentation . Explore Python’s Unicode HOWTO guide .
🌐
Medium
medium.com › @anala007 › dealing-with-the-unicodedecodeerror-in-pandas-when-reading-csv-files-edc4987bf68b
Dealing with the UnicodeDecodeError in Pandas When Reading CSV Files | by Arun | Medium
June 12, 2023 - This approach is more versatile as chardet will make a good guess on the encoding type, enabling you to read the file correctly. Another strategy is to ignore the errors and replace problematic characters with a replacement character. However, this approach could lead to data loss. Therefore, it’s generally only a good idea if there are only a few problematic characters and they are not significant to your data analysis. Here’s how to do it: import pandas as pd df = pd.read_csv('file.csv', encoding='utf-8', errors='replace')
🌐
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.
🌐
GitHub
github.com › pandas-dev › pandas › issues › 21118
to_csv failing with encoding='utf-16' · Issue #21118 · pandas-dev/pandas
May 18, 2018 - IO CSVread_csv, to_csvread_csv, to_csvRegressionFunctionality that used to work in a prior pandas versionFunctionality that used to work in a prior pandas version ... df.to_csv('test.gz', sep='~', header=False, index=False,compression='gzip',line_terminator='\r\n',encoding='utf-16', na_rep='') /opt/anaconda/lib/python3.6/encodings/ascii.py in decode(self, input, final) 24 class IncrementalDecoder(codecs.IncrementalDecoder): 25 def decode(self, input, final=False): ---> 26 return codecs.ascii_decode(input, self.errors)[0] 27 28 class StreamWriter(Codec,codecs.StreamWriter): UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: ordinal not in range(128)
Author: pandas-dev
🌐
Plain English
python.plainenglish.io › easy-ways-to-handle-unicodedecodeerrors-when-reading-csv-files-in-pandas-84c7aad1d5ac
Easy Ways To Handle UnicodeDecodeErrors When Reading CSV Files in Pandas | by Gabriel Ejiro | Python in Plain English
November 10, 2023 - Some of the most common encodings for Windows systems include: # UnicodeEscape import pandas as pd filepath = r"C:\path\to\your\file.csv" df = pd.read_csv(filepath, encoding='unicode_escape')
🌐
Quora
quora.com › How-do-I-fix-a-Unicode-error-while-reading-a-CSV-file-with-a-pandas-library-in-Python-3-6
How to fix a Unicode error while reading a CSV file with a pandas library in Python 3.6 - Quora
Quora is a place to gain and share knowledge. It's a platform to ask questions and connect with people who contribute unique insights and quality answers.
🌐
GitHub
github.com › pandas-dev › pandas › issues › 17097
Bug: On Python 3 to_csv() encoding defaults to ascii if the dataframe contains special characters. · Issue #17097 · pandas-dev/pandas
July 27, 2017 - A string representing the encoding to use in the output file, defaults to ‘ascii’ on Python 2 and ‘utf-8’ on Python 3. Therefore being on Python 3 I expect test1.csv and test2.csv to be utf8. However while test1.csv is encoded in utf8, test2.csv is encoded in ascii, if I want the correct encoding I have to explicitely add the encoding to produce the correct result as test3.csv.
Author: pandas-dev
🌐
codelessgenie
codelessgenie.com › blog › unicode-encode-error-when-writing-pandas-df-to-csv
How to Fix UnicodeEncodeError When Writing Pandas DataFrame to CSV (After Combining Excel Files) — CodeLessGenie.com
UnicodeEncodeError when writing a Pandas DataFrame to CSV after combining Excel files is a common but solvable issue. Start by explicitly specifying encoding='utf-8'—this fixes 90% of cases.
🌐
GitHub
github.com › pandas-dev › pandas › issues › 44323
to_csv() enconding option "utf-8-BOM" · Issue #44323 · pandas-dev/pandas
November 5, 2021 - Hey, could there be a way to save csvs as "utf-8-BOM" encoded? Because Excel needs the BOM to open csvs correctly. Everytime I save a csv with Pandas I have to open it with Notepad++ and change the encoding from utf-8 to uf8-BOM so that I can open it with Excel.
Author: pandas-dev
🌐
Dasboardai
dasboardai.com › blog › how-do-i-fix-an-unicode-error-in-python
How to fixed Encoding errors in pandas - DasBoardai.com
df = pd.read_csv('sales_data_sample.csv', encoding_errors='ignore') # Or Try This df = pd.read_csv('sales_data_sample.csv', encoding='unicode_escape') Copy Code ... import chardet # Open the file in binary mode to detect encoding with open('file.csv', 'rb') as f: result = chardet.detect(f.read()) encoding = result['encoding'] print(encoding) df = pd.read_csv('sales_data_sample.csv', encoding=encoding) ... Handling encoding errors in Pandas, especially when reading CSV files, is a common challenge when dealing with data from various sources.