ValueError                                Traceback (most recent call last)
<ipython-input-12-1dc462ae8893> in <module>()
15 print('cv prepared!')
16 return df_x.astype(np.float64)
---> 17 df_test = get_feature(test_data,all_table,ready_cols,vec_col)
18 df_train = get_feature(train_data,all_table,ready_cols,vec_col) <ipython-input-12-1dc462ae8893> in get_feature(df, all_data, cols, vec_col)
9 cv=CountVectorizer()
10 for feature in vec_col:
---> 11 cv.fit(all_data[feature])
12 df_a = cv.transform(df[feature])
13 df_x = sparse.hstack((df_x, df_a))

def get_feature(df,all_data,cols,vec_col):
  enc = OneHotEncoder()
  df_x=np.int64(df[cols])
  cv=CountVectorizer()
  for feature in vec_col:
    cv.fit(all_data[feature])
    df_a = cv.transform(df[feature])
    df_x = sparse.hstack((df_x, df_a))
    print('Done Feature '+ str(feature))
  print('cv prepared!')
  return df_x.astype(np.float64)

原因分析:我的all_data中存在nan的数据,我在数据读入的时候使用了all_table.fillna(-1),我理解只会填充空值,但是all_table中原本为nan的值,不会改变。改为all_table.fillna(-1),可执行。

np.nan is an invalid document, expected byte or unicode string.的更多相关文章

  1. numpy中np.nan(pandas中NAN)

    转自:http://blog.csdn.net/xiaodongxiexie/article/details/54352889 在处理数据时遇到NAN值的几率还是比较大的,有的时候需要对数据值是否为n ...

  2. 【原创】数据处理中判断空值的方法(np.isnan、is np.nan和pd.isna)比较

      转载请注明出处:https://www.cnblogs.com/oceanicstar/p/10869725.html  1.np.isnan(只有数组数值运算时可使用) 注意:numpy模块的i ...

  3. 【Problems】:JSON parse error: Invalid UTF-8 start byte 0xbd;

    简单记录一下 ,我本地开发环境这样写测试时没有问题, @ApiOperation(value="取消关注") @PostMapping("cancelFollow&quo ...

  4. Unity3D 集成 Face++ FacePlusPlus httpClient http协议 byte数组转string

    //開始由于要实现跨平台.考虑过用curl封装c++的dll(android *.so)的方式,在c#Dllimport实现 //后来发现Unity3D本身支持http协议.且face++的api都是 ...

  5. expected number,sequence,or string.map evaluated instead of freemarker.template.smplehash

    expected number,sequence,or string.map evaluated instead of freemarker.template.smplehash 使用freemark ...

  6. 深入 JAVA里面关于byte数组和String之间的转换问题

    把byte转化成string,必须经过编码.  例如下面一个例子:  importjava.io.UnsupportedEncodingException; publicclass test{ pub ...

  7. Spring Scheduled定时任务报错 java.lang.IllegalStateException: Encountered invalid @Scheduled method 'xxx': For input string: "2S"

    报错信息如下: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ding ...

  8. C# byte[]数组和string的互相转化 (四种方法)

    C# byte[]数组和string的互相转化 (四种方法) 第一种 [csharp] view plain copy string str = System.Text.Encoding.UTF8.G ...

  9. java byte数组与String的相互转换

    String  ->   byte数组 String str = "abc天"; byte[] btr = str.getBytes(); System.out.printl ...

随机推荐

  1. 在Xcode11上开发“面向低于iOS13版本的App”时的一些注意点

    相关知识: https://blog.csdn.net/BUG_delete/article/details/103699563 'AppDelegate' is only available in ...

  2. Asp.Net Mvc 控制器详解

    理解控制器 控制器的角色 (1)中转作用:控制器通过前面的学习大家应该知道它是一个承上启下的作用,根据用户输入,执行响应行为(动 作方法),同时在行为中调用模型的业务逻辑,返回给用户结果(视图). ( ...

  3. Spring Boot 在启动时进行配置文件加解密

    Spring Boot Application 事件和监听器 寻找到application.yml的读取的操作. 从spring.factories 中查看到 # Application Listen ...

  4. rust 九九乘法表

    fn main(){ for i in 1..10 { for j in 1..i+1 { print!("{}*{}={:<2} ",j,i,i*j); } print!( ...

  5. cb36a_c++_STL_算法_区间的比较equal_mismatch_lexicographical_compare

    *cb36a_c++_STL_算法_区间的比较equal_mismatch_lexicographical_compare 区间:容器中的全部数据或者部分数据,都叫做区间 equal(b,e,b2), ...

  6. Redis 数据结构 之 SDS

    SDS(simple dynamic string),简单动态字符串.s同时它被称为 Hacking String.hack 的地方就在 sds 保存了字符串的长度以及剩余空间.sds 的实现在 sd ...

  7. nginx在windows系统中启动、重启、停止,常用命令

    cmd终端在进入到nginx的安装目录下使用对应命令 查看nginx的版本号:nginx -v 启动nginx:start nginx 快速停止或关闭nginx:nginx -s stop 正常停止或 ...

  8. MySql索引要注意的8个事情

    设计好MySql索引可以让你的数据库查询效率大为提高.设计MySql索引的时候,有一些问题需要值得我们注意的: 1,创建MySql索引 对于查询占主要的应用来说,索引显得尤为重要.很多时候性能问题很简 ...

  9. junit搭建自动化测试框架(一)

    这里主要使用Junit搭建一个分层的自动化测试框架.这就是一个有业务逻辑的单元测试的思想.灵活性很大,对测试人员的代码能力要求较高. 以登录QQ邮箱为例,数据源使用了集合接口Map.借鉴了MVC的思想 ...

  10. CentOS 7 下安装 MySQL 8.0

    前言 本篇文章主要介绍在 CentOS 7 环境下安装 MySQL 8.0. 正文 1. 配置yum源 首先在 https://dev.mysql.com/downloads/repo/yum/ 找到 ...