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 ...
随机推荐
- VMWare的三种网络连接方式
VMWare和主机的三种网络连接方式 桥接 这种模式下,虚拟机通过主机的网卡与主机通信,如果主机能够上网,则虚拟机也能联网. 在虚拟机中,需要将虚拟机的IP配置为与主机处于同一网段. 虚拟机也可以与同 ...
- OpenSSH详解
OpenSSH详解(思维导图) 1. SSH概述 SSH 软件架构 认证方式 2. OpenSSH 2.1 客户端程序ssh 配置文件 ssh命令 客户端免密登录 scp sftp 2.2 服务端程序 ...
- Brainman(规律题)【数学思想】
Brainman 题目链接(点击) Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 12942 Accepted: 650 ...
- cookie常用函数
cookie常用函数 web_add_cookie:添加新的cookie或修改已经存在的cokkies web_remove_cookie:删除指定的cookie web_cleanup_cookie ...
- 基于flask的城市空气质量分析系统
1.1 系统功能 在对主要需求进行分析后,确定系统由以下几个模块组成. 1) 用户信息管理: 该部分主要完成系统管理员的增加.删除.编辑和访问控制权限等操作. 2) 数据管理: 该部分主要完成后台存 ...
- 一个老牌程序员说:做Java开发,怎么可以不会这 20 种类库和 API
- opencv C++ Mat构造函数
cv::Scalar scalar1(v); cv::Mat mat3(size,CV_8UC1,scalar1); std::cout<<mat3<<std::endl; s ...
- android 6.0 以上在doze模式精确定时
public static void start12hAlarm() { int seconds = TIMERLENGTH; ECMLog.i_ecms(CLASS_TAG, " star ...
- 基于MarkDown和Github图床以及SourceTree的一站式文章编辑和发布
标题: 基于MarkDown和Github图床以及SourceTree的一站式文章编辑和发布 作者: 梦幻之心星 sky-seeker@qq.com 标签: [MarkDown,Github,图床,S ...
- Python3-datetime模块-日期与时间
官方文档 http://python.usyiyi.cn/translate/python_352/library/datetime.html 代码示例 from datetime import da ...