使用readr包导入时,解析器与.csv文件中的列名不匹配 [英] Parser does not match column name in .csv file when importing using readr package

查看:344
本文介绍了使用readr包导入时,解析器与.csv文件中的列名不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将.csv文件导入R,其中包含来自BLS的就业数据.当我尝试导入数据时,除第一列外,所有列均有效,这给了我错误:

I am trying to import a .csv file into R that contains employment data from the BLS. When I attempt to import the data, every column works except the first, which gives me the error:

EmpEd <- read_csv("~/Documents/Research/Global Business Research Center/Future of Education/EmploymentbyEd.csv", 
              col_types = cols(`Date` = col_date(format = "%B-%y"),
                               `LessHsPart` = col_number(),
                               `HsPart` = col_number(),
                               `SomeUgPart` = col_number(),
                               `UgHighPart` = col_number(),
                               `LessHsUp` = col_number(),
                               `HsUp` = col_number(),
                               `SomeUgUp` = col_number(),
                               `UGHighUp` = col_number()))

以下命名的解析器与列名称不匹配:日期

The following named parsers don't match the column names: Date

我已经检查了.csv文件,这是正确的列名.我不确定我的代码中有什么给我错误.与我自己格式化日期的方式有关吗?

I have checked the .csv file and that is the right column name. I'm not sure what in my code is giving me the error. Does it have to do with the way I am formatting the dates themselves?

原始数据集可在此处下载:

The original dataset can be downloaded here:

https://drive.google.com/file/d/0BzuJJ0j4Lyi6R1h0T0VZOUNyaEU/view?usp = sharing

推荐答案

在Date之前您有一个不可见的字符,无法以友好的方式进行解析.

You have an invisible character before Date which does not parse in a friendly way.

您还使用了readr的旧版本.较新的版本会将其作为警告而不是错误.对于较新的版本,应该可以轻松读取文件,但是在引用日期"列时可能会遇到麻烦.

You are also using an old version of readr. Newer versions will give that as a warning rather than an error. With a newer version the file should be read in easily, but you may have trouble referring to the Date column.

在您喜欢的文本编辑器中打开文件.删除第一行,然后手工重写. (虽然您应该能够复制和粘贴日期"以外的所有内容,但不要复制和粘贴.)

Open the file in your favorite text editor. Delete the first line and rewrite it by hand. (Not copy and paste, though you should be able to copy and paste everything but 'Date'.)

由于您在这里有日期,所以我建议您不要在Excel中打开此文件.记事本可能有效,但我的建议是emax或vim.

Since you have dates here I would advise against ever opening this file in Excel. Notepad may work, but my suggestion would be emax or vim.

这篇关于使用readr包导入时,解析器与.csv文件中的列名不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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