np.nan is an invalid document, expected byte or unicode string.
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.的更多相关文章
- numpy中np.nan(pandas中NAN)
转自:http://blog.csdn.net/xiaodongxiexie/article/details/54352889 在处理数据时遇到NAN值的几率还是比较大的,有的时候需要对数据值是否为n ...
- 【原创】数据处理中判断空值的方法(np.isnan、is np.nan和pd.isna)比较
转载请注明出处:https://www.cnblogs.com/oceanicstar/p/10869725.html 1.np.isnan(只有数组数值运算时可使用) 注意:numpy模块的i ...
- 【Problems】:JSON parse error: Invalid UTF-8 start byte 0xbd;
简单记录一下 ,我本地开发环境这样写测试时没有问题, @ApiOperation(value="取消关注") @PostMapping("cancelFollow&quo ...
- Unity3D 集成 Face++ FacePlusPlus httpClient http协议 byte数组转string
//開始由于要实现跨平台.考虑过用curl封装c++的dll(android *.so)的方式,在c#Dllimport实现 //后来发现Unity3D本身支持http协议.且face++的api都是 ...
- 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 ...
- 深入 JAVA里面关于byte数组和String之间的转换问题
把byte转化成string,必须经过编码. 例如下面一个例子: importjava.io.UnsupportedEncodingException; publicclass test{ pub ...
- 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 ...
- C# byte[]数组和string的互相转化 (四种方法)
C# byte[]数组和string的互相转化 (四种方法) 第一种 [csharp] view plain copy string str = System.Text.Encoding.UTF8.G ...
- java byte数组与String的相互转换
String -> byte数组 String str = "abc天"; byte[] btr = str.getBytes(); System.out.printl ...
随机推荐
- @codeforces - 506C@ Mr. Kitayuta vs. Bamboos
目录 @description@ @solution@ @accepted code@ @details@ @description@ n 个竹子,第 i 个竹子初始高度 hi,在每天结束时将长高 a ...
- Codeforces Round #561 (Div. 2) A Tale of Two Lands 【二分】
A Tale of Two Lands 题目链接(点击) The legend of the foundation of Vectorland talks of two integers xx and ...
- turtle 画一朵花
操纵海龟绘图有着许多的命令,这些命令可以划分为两种:一种为运动命令,一种为画笔控制命令1. 运动命令:forward(degree) #向前移动距离degree代表距离backward(degree ...
- 使用Bundle在Activity中交换数据
大概过程 编写demo activity_main.xml <?xml version="1.0" encoding="utf-8"?> <R ...
- S7-200 PLC内部+5VDC电源的负载能力
S7-200 PLC内部+5VDC电源的负载能力 S7-200 CPU模块提供DC5V和24V电源:当有扩展模块时,CPU通过I/O总线为其提供5V电源,所有扩展模块的SV电源消耗之和不能超过该CPU ...
- Head_First_Python(中文版)完整版PDF免费下载_百度云盘
Head_First_Python(中文版)完整版PDF免费下载_百度云盘 提取码:bjbg 本书特色 根据认知科学和学习理论的最新研究成果,这本书采用一种适合大脑的丰富格式娓娓道来,而不是长篇累牍地 ...
- WeChair——团队展示
这个作业属于哪个课程 软件工程 (福州大学至诚学院 - 计算机工程系) 团队名称 WeChair 这个作业要求在哪里 团队作业第一次 这个作业的目标 团队合作,项目开发 作业正文 如下 其他参考文献 ...
- Netty源码分析之自定义编解码器
在日常的网络开发当中,协议解析都是必须的工作内容,Netty中虽然内置了基于长度.分隔符的编解码器,但在大部分场景中我们使用的都是自定义协议,所以Netty提供了 MessageToByteEnco ...
- Linux下9种优秀的代码比对工具推荐
大家好,我是良许. 在我们编写代码的时候,我们经常需要知道两个文件之间,或者同一个文件不同版本之间有什么差异性.在 Windows 下有个很强大的工具叫作 BeyondCompare ,那在 Linu ...
- Git安装及配置SSH-Key
下载Git 打开 https://git-scm.com/downloads 选择windows, 下载并安装. 配置全局用户名及邮箱 配置用户名 git config --global user.n ...