Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5155

Beginners • Re: Output to .csv file in Chinese? Characters

$
0
0
I'm afraid you are providing a lot of information about symptoms but nothing about the actual files or scripts involved
I have a Python3 program that outputs data daily to a .csv file. This data is just numbers, usually between 10000 and 30000.
How are you constructing the CSV file? Are you simply opening a file in Python, converting all variables to STR, then writing out the rows? What does the CSV file itself look like. Seeing the contents would help.
I don't read the data very often but having tried to read it today, instead of the file containing numbers using Libre Office on the Pi the system reports: 'The data could not be loaded completely because the maximum number of characters per cell was exceeded'.
In fact it does not display the file at all.
Looking at it using another program like Geany may show you something
I am able to get my program to send just one number (say 2345) to a csv file but instead of reading what I expect, it appears to be saved in what I can only guess is a Chinese or Japanese font.
Is that what you are seeing in Libre Office?
It always used to work and display perfectly but I have a feeling that this may have happened after an OS upgrade.
(Incidentally, if I copy my .csv file on a USB stick to be displayed on a Windows 10 PC running Excel, the file displays the numbers correctly)
The spreadsheet in Libre Office appears to be defaulted to typeface: Unicode (UTF-16).
UTF-16 is a character encoding and not a typeface.
Could someone please advise what is the standard UK typeface that should be used and if this can then be set to be the default in Libre Office.
Thank you
Here's an example taken from

Code:

import csvwith open('eggs.csv', 'w', newline='') as csvfile:    spamwriter = csv.writer(csvfile, delimiter=' ',                            quotechar='|', quoting=csv.QUOTE_MINIMAL)    spamwriter.writerow(['Spam'] * 5 + ['Baked Beans'])    spamwriter.writerow(['Spam', 'Lovely Spam', 'Wonderful Spam'])
The resulting eggs.csv looks like this

Code:

$ more eggs.csvSpam Spam Spam Spam Spam |Baked Beans|Spam |Lovely Spam| |Wonderful Spam|
You can use the file comand to find the character set but I don't think that is your problem. I think it may be the actual CSV creation

Code:

$ file -bi eggs.csvtext/plain; charset=us-ascii
I was able to open the CSV file in Libre Office CALC

Statistics: Posted by DS256 — Sun Oct 13, 2024 12:12 am



Viewing all articles
Browse latest Browse all 5155

Trending Articles