是否可以在分块数据上使用DictVectorizer? [英] Is it possible to use DictVectorizer on chunked data?

查看:81
本文介绍了是否可以在分块数据上使用DictVectorizer?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用python pandas csv阅读器导入分块数据,以克服内存错误,并使用DicVectorizer将字符串转换为浮点dtype.但是我可以看到两个不同的字符串在转换后具有相同的代码.我们是否有其他选择/选项可以对分块数据进行数据类型转换?

I am trying to import chunked data using python pandas csv reader,to overcome memory error, and use DicVectorizer to transform string to float dtypes. But I could see two different strings are having same codes after transformation. Do we have alternative/option to do the data type transformation on chunked data?

推荐答案

在Pandas 0.19中,您可以在read_csv中将列声明为分类".参见文档.

In Pandas 0.19, you can declare columns as Categorial in read_csv. See documentaion.

因此,以该文档为例,您可以像这样在csv中键入名为col1的列并减少内存占用:

So as an example for the doc, you can type a column named col1 in your csv like this and reduce memory footprint:

pd.read_csv(StringIO(data), dtype={'col1': 'category'})

这篇关于是否可以在分块数据上使用DictVectorizer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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