为何Pandas将我的Numpy Float32强制为Float64? [英] Why does Pandas coerce my numpy float32 to float64?

查看:436
本文介绍了为何Pandas将我的Numpy Float32强制为Float64?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么熊猫在这段代码中将我的numpy float32强制为float64:

Why does Pandas coerce my numpy float32 to float64 in this piece of code:

>>> import pandas as pd
>>> import numpy as np
>>> df = pd.DataFrame([[1, 2, 'a'], [3, 4, 'b']], dtype=np.float32)
>>> A = df.ix[:, 0:1].values
>>> df.ix[:, 0:1] = A
>>> df[0].dtype
dtype('float64')

这个行为对我来说似乎很奇怪,不知道这是否是一个错误.我使用的是Pandas版本0.17.1(更新的PyPI版本),并且我注意到最近已解决了一些强制性错误,请参见

The behavior seems so odd to me that wonder if it is a bug. I am on Pandas version 0.17.1 (updated PyPI version) and I note there has been coercing bugs recently addressed, see https://github.com/pydata/pandas/issues/11847 . I haven't tried the piece of code with an updated GitHub master.

这是一个错误还是我误解了熊猫的某些功能"?如果它是一项功能,那么我该如何解决?

Is it a bug or do I misunderstand some "feature" in Pandas? If it is a feature, then how do I get around it?

(强制性问题与我最近问过的有关Pandas任务执行情况的问题有关:

(The coercing problem relates to a question I recently asked about the performance of Pandas assignments: Assignment of Pandas DataFrame with float32 and float64 slow)

推荐答案

我认为值得将此作为GitHub问题发布.行为肯定是不一致的.

I think it is worth posting this as a GitHub issue. The behavior is certainly inconsistent.

代码根据DataFrame是否为混合类型而采用不同的分支(

The code takes a different branch based on whether the DataFrame is mixed-type or not (source).

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