pandas ValueError:缓冲区数据类型不匹配,预期为“float64_t”但得到“float”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14984667/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 20:40:02  来源:igfitidea点击:

ValueError: Buffer dtype mismatch, expected 'float64_t' but got 'float'

pythonpandas

提问by wuwucat

There is a DataFrame 'modtso':

有一个 DataFrame 'modtso':

In [4]: modtso
Out[4]: 
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 74006 entries, 2002-07-27 15:00:00 to 2010-12-31 22:58:08
Data columns:
0    74006  non-null values
dtypes: float32(1)

In [5]: modtso[1:10]
Out[5]: 
                         0
2002-07-27 16:01:53   9.336845
2002-07-27 16:58:08   9.337487
2002-07-27 18:00:00   9.343308
2002-07-27 19:01:53   9.364368
2002-07-27 19:58:08   9.389445
...

Now I want to resample it as below:

现在我想重新采样如下:

a=modtso.resample('D',how='std')

it will raise a exception:

它将引发异常:

ValueError: Buffer dtype mismatch, expected 'float64_t' but got 'float'

what's the problem? how can I fix it? thanks

有什么问题?我该如何解决?谢谢

回答by Jeff

this is fully supported on 0.11-dev in 0.10 I think it will work, but your float32 will become float64 for almost any operation

这在 0.10 中的 0.11-dev 上完全支持我认为它会起作用,但是对于几乎任何操作,您的 float32 都将变为 float64

and FYI to convert types explicitly

和 FYI 显式转换类型

df.astype('float64')

see the examples here http://pandas.pydata.org/pandas-docs/dev/whatsnew.html#v0-11-0-march-2013

请参阅此处的示例 http://pandas.pydata.org/pandas-docs/dev/whatsnew.html#v0-11-0-march-2013

回答by wuwucat

do this can solve this problem:

这样做可以解决这个问题:

from numpy import float64
remod=float64(modtso[0]).resample('D',how=['std'])