这个
规模
确实似乎翻了一番。你可以
cast
返回到原始dtype:
cols = ['c', 'd', 'e']
df.with_columns(pl.col(c).mul(pl.col('a')).cast(df[c].dtype) for c in cols)
请注意,目前似乎没有方法在
Expr
,但这是一个
discussed feature
.
例子:
âââââââ¬ââââââ¬âââââââââââââââ¬âââââââââââââââ¬âââââââââââââââ
â a â b â c â d â e â
â --- â --- â --- â --- â --- â
â i64 â i64 â decimal[*,2] â decimal[*,3] â decimal[*,4] â
âââââââªââââââªâââââââââââââââªâââââââââââââââªâââââââââââââââ¡
â 1 â 3 â 2.11 â 1.100 â 1.1001 â
â 2 â 4 â 8.42 â 6.022 â 6.0004 â
âââââââ´ââââââ´âââââââââââââââ´âââââââââââââââ´âââââââââââââââ
已使用的输入:
from decimal import Decimal
df = pl.DataFrame({
"a": [1, 2],
"b": [3, 4],
"c": [Decimal('2.11'), Decimal('4.21')],
"d": [Decimal('1.10'), Decimal('3.011')],
"e": [Decimal('1.1001'), Decimal('3.0002')],
})