读取toad导出的csv文件后,奇怪的字符添加到第一列名称 [英] Weird characters added to first column name after reading a toad-exported csv file

查看:128
本文介绍了读取toad导出的csv文件后,奇怪的字符添加到第一列名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我读到使用Toad导出的R(read.csv("file_name.csv"))中的csv文件时,第一列名称之前都会带有以下字符"ï.. ".另外,在excel或notepad ++中打开csv文件也可以正确显示(没有前面的字符).这很麻烦,因为我的解决方法是在每次读取后重命名该列. 感谢您解决此问题!

Whenever I read a csv file in R (read.csv("file_name.csv")) that was exported using toad, the first column name is preceded by the following characters "ï..". Also, opening the csv file in excel or notepad++ shows up correctly (without the preceding characters). This is a hassle as my workaround has been to rename the column after each read. Thanks for any fix to this issue!


右键单击查询的结果集并选择
'快速导出->文件-> CSV文件'


The export was created in Toad by right-clicking on the result set of a query and selecting
'Quick Export -> File -> CSV File'

每个评论的更多详细信息:

More details per comment:

head(readLines('test_file.csv'),n=3)`<br>
[1] "ID,LOCATION" "12021,1204" "12281,1204"

推荐答案

尝试一下:

d <- read.csv("test_file.csv", fileEncoding="UTF-8-BOM")

这在R 3.0.0+中有效,并且删除了文件中的BOM(对于从Microsoft应用程序生成的文件常见的Excel,SQL Server)

This works in R 3.0.0+ and removes the BOM if present in the file (common for files generated from Microsoft applications: Excel, SQL server)

这篇关于读取toad导出的csv文件后,奇怪的字符添加到第一列名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆