- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
关于如何将系列(列)从浮点数转换为十进制数的任何想法?我在 Python 3.6 上。我已经阅读了 Decimal 文档,但它没有提供任何帮助。
df['rate'].dtype
Out[158]: dtype('float64')
Decimal(df['rate'])
Traceback (most recent call last):
File "C:\Users\user\Anaconda3\lib\site-packages\IPython
\core\interactiveshell.py", line 2862, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-159-88710e11f7cd>", line 1, in <module>
Decimal(df['rate'])
TypeError: conversion from Series to Decimal is not supported
最佳答案
你不能像这样投,你需要做
df['rate'] = df['rate'].apply(Decimal)
pandas
确实支持
Decimal
但你不能那样转换
In[28]:
from decimal import *
df = pd.DataFrame(np.random.randn(5,3), columns=list('abc'))
df['a'] = df['a'].apply(Decimal)
df
Out[28]:
a b c
0 -1.6122557830197199457700207858579233288764953... -1.865243 -0.836893
1 0.96962430214434858211092205237946473062038421... -0.105823 -0.842267
2 -0.9113389075755260471112251252634450793266296... -0.351389 -0.183489
3 1.22765470106414120721183280693367123603820800... -1.232627 -0.067909
4 -0.0376339704393285762185072940155805554240942... -0.445606 -0.080623
object
但 dtype 确实是
Decimal
:
In[29]:
type(df['a'].iloc[0])
Out[29]: decimal.Decimal
astype(Decimal)
它看起来像它工作但它没有:
In[38]:
df['b'].astype(Decimal)
Out[38]:
0 -1.86524
1 -0.105823
2 -0.351389
3 -1.23263
4 -0.445606
Name: b, dtype: object
In[39]:
df['b'] = df['b'].astype(Decimal)
type(df['b'].iloc[0])
Out[39]: float
关于python-3.x - 类型错误 : conversion from Series to Decimal is not supported,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47266531/
有没有人有嵌套 Intent 的好例子,尤其是在 #yes 和 #no 是子节点的情况下。我得到的情况是 API 返回的是 Intent 值,但输出文本来自“Anything else”! 最佳答案
我知道您可以转到 Watson Conversation 界面,右键单击工作区,然后下载工作区的 JSON,其中包含意图,如下所示:Is there any way to export intents
我能否在 Watson Conversation API 的对话流中使用节点条件中的意图置信度评级? 最佳答案 要做到这一点,请创建一个条件来寻找您的意图,然后检查置信度。 你会拥有的示例条件 #te
我找到了很多关于这个错误的帖子,但我可以找到克服它的方法。这是触发错误的代码: void main(){ float f{1.3}; } 为什么在初始化列表中没有像其他变量那样发生转换?例如,
我有以下代码。 #include using namespace std; class Base { public: virtual int f(){coutf(); ///base
Visual C++ 2017 和 gcc 5.4 产生 conversion from 'const unsigned char' to 'const float' requires a narro
我正在为 PIC18F2420 使用带有 xc8 1.35 编译器的 MPLABX 3.20,我收到了两个我不理解的奇怪警告: 这是生成警告的源代码之一 9 void write(Pin _Pin,
我正在尝试在 win32 API(无 mfc)上编写一些直接的 c++。有了这个更现代的 c++ 编译器,我得到: 警告 C4838:从“unsigned int”到“int”的转换需要收缩转换 它发
此代码采用用户输入(字符 C、T、B)和(int 0-24 和 0-60)来计算 parking 成本关于用户输入的车辆类型。 我怀疑错误发生在函数 charged 中,因此我无法在收到此错误的最后一
为什么在使用 tuple 或 Tuple 转换向量时会得到以下不同的结果? julia> a = [1, 2, 3] 3-element Vector{Int64}: 1 2 3 julia> tup
关闭。这个问题是opinion-based .它目前不接受答案。 想改善这个问题吗?更新问题,以便可以通过 editing this post 用事实和引文回答问题. 8年前关闭。 Improve t
我正在开发一个文件共享网站,我需要一种方法来对上传的文档进行截图。 该站点将支持多种文件格式,从纯文本到办公文档(doc、xls、ppt...)、视频(mpeg、avi...)、图像(jpg、gif、
在 VHDL 中是否有将整数类型对象转换为实数类型的通用转换函数? 这是针对测试平台的,因此可综合性不是问题。 最佳答案 您可以将整数转换为实数,如下所示: signal i: integer; si
如何在 Ocaml 中将字符串选项数据类型转换为字符串? let function1 data = match data with None -> "" | Some str -> s
我已经在 VHDL 中编写了一个算法,但是我有一条消息,我不明白“sra/sla 在这种情况下不能有这样的操作数。”。请问有什么帮助吗? library ieee; use ieee.std_logi
我经常需要将数据从一种类型转换为另一种类型,然后进行比较。一些运算符会先转换为特定类型,这种转换可能会导致效率损失。例如,我可能有 my $a, $b = 0, "foo"; # initial va
假设我在 IBM Watson 中配置了一个对话服务,可以识别以单词和片段形式给出的数字。例如,如果我有号码 1320 , 可以发送为 thirteen twenty或 thirteen two ze
也许我错过了一些显而易见的事情...在整个文档中,我似乎都认为Kotlin具有各种类型的序列,这些序列不能互操作。即使复制序列可能效率不高–当我需要将其作为语义相同但不同的类型传递给函数时,这也无济于
在我的Linux终端中,我想要使用QTcpSocket从qt运行以下“对话”: S user@domain:~ $ netcat 1.1.1.2 9230 R HELO SOME MORE I
我有一个模板函数,其中枚举类型转换为它的底层类型,工作正常,但我写了一个重载,它应该接受一个整数并返回它自己,它给我一个错误,指出 int 不是枚举类型。在我的模板中,这应该已经被过滤掉了。怎么了?
我是一名优秀的程序员,十分优秀!