Pandas dataframe to excel gives file is not UTF-8 encoded

2024/10/18 15:09:03

I'm working on lists that I want to export into an Excel file.

I found a lot of people advising to use pandas.dataframe so that's what I did. I could create the dataframe but when I try to export it to Excel, the file is empty, there is just the following message:

" Error! [file_pathway] is not UTF-8 encoded. Saving disabled. See console for more details".

I didn't see any more info on the console, and every example I found on the Internet leads to the same error message.

The different lists I'm using contain different types of data. So I try to convert every element I could into a UTF-8 encoded element. I couldn't do it for the "float" list nor for the "NoType" list.

After that, here is what I wrote :

d = {'Dataset_name': dataset_names, 'Parameter_name': para_names, 'Parameter_amount': para_amounts, 'Parameter_unit': para_units, 'Parameter_variable': para_variables, 'Parameter_formula': para_formulas}
df = pd.DataFrame(data=d)from pandas import ExcelWriter
writer = ExcelWriter('Ocelot_Export.xlsx')
df.to_excel(writer, encoding='utf8', index=False)
writer.save()

The dataframe is correct, as I can print it in Jupyter Notebook. The only problem is the exportation. Please let me know if you have any idea about what's wrong.

Answer

The cause of this problem is likely just that jupyter is unable to display .xlsx files. Try downloading the file from jupyter (checkbox next to the file name -> "Download" button near the page header) onto your local machine and open it using excel.

2020 Update: If you're using Jupyter Lab, jupyterlab-spreadsheet is a great way to view excel files without leaving your browser.

https://en.xdnf.cn/q/73029.html

Related Q&A

Finding complex roots from set of non-linear equations in python

I have been testing an algorithm that has been published in literature that involves solving a set of m non-linear equations in both Matlab and Python. The set of non-linear equations involves input v…

Python on Raspberry Pi user input inside infinite loop misses inputs when hit with many

I have a very basic parrot script written in Python that simply prompts for a user input and prints it back inside an infinite loop. The Raspberry Pi has a USB barcode scanner attached for the input.wh…

How to append two bytes in python?

Say you have b\x04 and b\x00 how can you combine them as b\x0400?

Pythonic way to write a function which modifies a list?

In python function arguments are passed by object reference. This means the simplest code to modify a list will modify the object itself.a = [1,2,3]def remove_one(b):b.remove(1)remove_one(a) print(a)T…

Trying different functions until one does not throw an exception

I have some functions which try various methods to solve a problem based on a set of input data. If the problem cannot be solved by that method then the function will throw an exception.I need to try t…

Python: Extracting lists from list with module or regular expression

Im trying to extract lists/sublists from one bigger integer-list with Python2.7 by using start- and end-patterns. I would like to do it with a function, but I cant find a library, algorithm or a regula…

Converting hard integral to lambda function with lambdify

I would like to lambdify the function Integral(t**t,(t,0,x)). It works, but my new function, which was returned by lambdify, doesnt return a number but only sympy.integrals.integrals.Integral class. Bu…

python topN max heap, use heapq or self implement?

theres heapq in python, for general usage. i want recording topN(0~20) for 10e7 records.if use heapq, should use - to translate max to min; and recording a min number of bottom, to call heapq.heappushp…

QSortFilterProxyModel returning artificial row

Im using a QSortFilterProxyModel to filter results from a QAbstractListModel. However, Id like to return a first entry which is not present in the original model, that is, its somehow artificial.This i…

@login_required is losing the current specified language

I am using i18n_patterns to internationalize my app and its working except when I click on a link that requires login (a view protected by @login_required decorator), I am being redirected to the login…