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 - IO CSVread_csv, to_csvread_csv, to_csvOutput-Formatting__repr__ of pandas objects, to_string__repr__ of pandas objects, to_string ... 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.
Author: pandas-dev
Discussions

Pandas DataFrame.to_csv() struggling with encoding
How are you actually opening the generated CSV file? More on reddit.com
🌐 r/learnpython
9
1
January 14, 2021
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
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 ...
🌐
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"))
🌐
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?

🌐
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 - When you save this DataFrame to a CSV file using utf-8 encoding and later read it using read_csv, you should specify utf-8 as the encoding to correctly handle these special characters: Here’s a list of encoding options that you can use with the read_csv function in Pandas: df = pd.read_csv('example_utf8.csv', encoding='utf-8') print(df) ... Let’s explore several types of encoding method which are supported by Pandas. UTF-8 is the most widely used encoding format for text data...
🌐
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 - 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. A: Yes, Python 3 handles UTF-8 more effectively. However, for compatibility with Excel, consider using utf-8-sig or utf-16. A: Use a text editor or tools like file command (Linux/Mac) or Notepad++ to check the encoding of the file.
🌐
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 - However, this also means that the number of characters encoded by specifically UTF-8, is limited (just like ASCII). There are other UTFs (such as 16), however, this raises a key limitation, especially in the field of data science: sometimes we either don't need the non-UTF characters or can't process them, or we need to save on space. Therefore, here are three ways I handle non-UTF-8 characters for reading into a Pandas dataframe:
🌐
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 - Pandas usually reads CSV files with ‘utf-8’ encoding by default. However, if your file uses a different encoding, you might meet the formidable ‘UnicodeDecodeError.’ To avoid this, a simple fix is to determine/identify your file’s encoding and explicitly mention it in your code.
🌐
GitHub
github.com › pandas-dev › pandas › issues › 21118
to_csv failing with encoding='utf-16' · Issue #21118 · pandas-dev/pandas
May 18, 2018 - Code Sample: 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 Incrementa...
Author: pandas-dev
🌐
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
🌐
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.
🌐
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
However, the process isn’t always flawless, and you might occasionally encounter errors such as the UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf3 in position 74188: invalid continuation byte`. 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.