Python中文
首页
教程
问答
标签
搜索
登录
注册
使用pandas指定dtype float32。在pandas 0.10.1上读取csv
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我试图用pandas<code>read_csv</code>方法读取一个简单的空格分隔文件。然而,熊猫似乎没有遵守我的论点。也许我说的不对?</p> <p>我已经将我对这个简单测试用例的<code>read_csv</code>的稍微复杂的调用提炼出来。实际上,我在“真实”场景中使用了<code>converters</code>参数,但为了简单起见,我删除了这个参数。</p> <p>下面是我的ipython会话:</p> <pre><code>>>> cat test.out a b 0.76398 0.81394 0.32136 0.91063 >>> import pandas >>> import numpy >>> x = pandas.read_csv('test.out', dtype={'a': numpy.float32}, delim_whitespace=True) >>> x a b 0 0.76398 0.81394 1 0.32136 0.91063 >>> x.a.dtype dtype('float64') </code></pre> <p>我也试过用这个和<code>dtype</code>的<code>numpy.int32</code>或<code>numpy.int64</code>一起使用。这些选择导致异常:</p> <pre><code>AttributeError: 'NoneType' object has no attribute 'dtype' </code></pre> <p>我假设<code>AttributeError</code>是因为pandas不会自动尝试将浮点值转换/截断为整数?</p> <p>我在一台32位机器上运行32位版本的Python。</p> <pre><code>>>> !uname -a Linux ubuntu 3.0.0-13-generic #22-Ubuntu SMP Wed Nov 2 13:25:36 UTC 2011 i686 i686 i386 GNU/Linux >>> import platform >>> platform.architecture() ('32bit', 'ELF') >>> pandas.__version__ '0.10.1' </code></pre>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<pre><code>In [22]: df.a.dtype = pd.np.float32 In [23]: df.a.dtype Out[23]: dtype('float32') </code></pre> <p>在熊猫0.10.1的情况下,上面的方法对我来说很好</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
无法使用Django/mongoengine连接到MongoDB(身份验证失败)
9 回答
无法使用Django\u mssql\u后端迁移到外部hos
4 回答
无法使用Django&Python3.4连接到MySql
4 回答
无法使用Django+nginx上载媒体文件
10 回答
无法使用Django1.6导入名称模式
5 回答
无法使用Django1.7和mongodb登录管理站点
8 回答
无法使用Djangoadmin创建项目,进程使用了错误的路径,因为我事先安装了错误的Python
7 回答
无法使用Djangockedi验证CBV中的字段
5 回答
无法使用Djangocketditor上载图像(错误400)
3 回答
无法使用Djangocron进行函数调用
9 回答
无法使用Djangofiler djang上载文件
6 回答
无法使用Djangokronos
7 回答
无法使用Djangomssql provid
10 回答
无法使用Djangomssql连接到带有Django 1.11的MS SQL Server 2016
1 回答
无法使用Djangomssq迁移Django数据库
2 回答
无法使用Djangonox创建用户
6 回答
无法使用Djangopyodb从Django查询SQL Server
3 回答
无法使用Djangopython3ldap连接到ldap
4 回答
无法使用Djangoredis连接到redis
8 回答
无法使用Django中的FK创建新表
2 回答