I want to convert my array to csv file. I have an array named result.
result = ['Prenzlauer Berg Nordwest' 'Neuköllner Mitte/Zentrum' 'Rixdorf' ...
'Parkviertel' 'Frankfurter Allee Süd FK' 'Helmholtzplatz']
I try to write an array to csv file using np.savetxt('output.csv', result, delimiter=',', fmt='%s')
But, in my csv file shows
Error! output.csv is not UTF-8 encoded. Saving disabled. See console for more details.
How do i fix this?
Thank youu
The csv file you are using likely does not support UTF-8 text formatting so some special characters might not work. Try following these steps to turn on utf-8 encoding in your csv file: https://www.webtoffee.com/how-to-save-csv-excel-file-as-utf-8-encoded/
Or try creating a new csv file. I think np can set the csv file to the correct type automatically upon creation.
In an ipython
session running in linux
, your code works:
In [50]: result = ['Prenzlauer Berg Nordwest', 'Neuköllner Mitte/Zentrum', 'Rixdorf',
...: 'Parkviertel', 'Frankfurter Allee Süd FK', 'Helmholtzplatz']
In [51]: result = np.array(result)
In [52]: result
Out[52]:
array(['Prenzlauer Berg Nordwest', 'Neuköllner Mitte/Zentrum', 'Rixdorf',
'Parkviertel', 'Frankfurter Allee Süd FK', 'Helmholtzplatz'],
dtype='<U24')
In [53]: np.savetxt('output.csv', result, delimiter=',', fmt='%s')
In [54]: cat output.csv
Prenzlauer Berg Nordwest
Neuköllner Mitte/Zentrum
Rixdorf
Parkviertel
Frankfurter Allee Süd FK
Helmholtzplatz
And in an editor the file type is utf8.
If you open the csv file in Excel and save as "CSV UTF-8(Comma delimited)(*.csv)", it works perfectly. I just did that and it works.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.