为什么pandas Decimal 插入的数据与读取的数据有差别?

dolphindb:v2.00.10.2 Python SDK  1.30.22.6  复现代码:
import dolphindb,pandas
from pandas._libs.tslibs.timestamps import Timestamp 
from decimal import Decimal

s = dolphindb.session(protocol=dolphindb.settings.PROTOCOL_DDB)
s.connect("127.0.0.1",8848,"admin","123456")

ds=[{'symbol': 'E',                        
  'datetime': Timestamp('2023-12-17 12:45:11.437000'),                                    
  'ask': Decimal('0.00037100'),              
  'bid': Decimal('0.00036980'),              
  'price': Decimal('0.00036930'),            
  'total_base': Decimal('126890.1'),         
  'total_quote': Decimal('45.48712794')},    
 {'symbol': 'B',                       
  'datetime': Timestamp('2023-12-17 12:45:11.709000'),                                    
  'ask': Decimal('41924.92000000'),          
  'bid': Decimal('41924.91000000'),          
  'price': Decimal('41924.91000000'),        
  'total_base': Decimal('24514.60467'),      
  'total_quote': Decimal('1034588710.08652780')}]     
  
dy=pandas.DataFrame(ds)

s.upload({"dy":dy})
s.run("select * from dy"),dy  

Out[1]: 
(  symbol                datetime             ask             bid           price   total_base          total_quote
 0      E 2023-12-17 12:45:11.437      0.00037100      0.00036980      0.00036930     126890.1          45.48712794
 1      B 2023-12-17 12:45:11.709  41924.92000000  41924.91000000  41924.91000000  245146046.7  1034588710.08652780,
   symbol                datetime             ask             bid           price   total_base          total_quote
 0      E 2023-12-17 12:45:11.437      0.00037100      0.00036980      0.00036930     126890.1          45.48712794
 1      B 2023-12-17 12:45:11.709  41924.92000000  41924.91000000  41924.91000000  24514.60467  1034588710.08652780)


为什么原始值 24514.60467 插入后就变成了 245146046.7
请先 登录 后评论

1 个回答

Polly

因为 DolphinDB 的 Decimal 类型是有位数的,直接上传 df,会以你第一条记录作为位数的约束,第一条数据是 126890.1,所以之后的都会保留 1 位。你可以不以直接上传 DF 的方式,可以先创建一个空表,规定好数据类型,然后往里面追加数据。

请先 登录 后评论
  • 1 关注
  • 0 收藏,292 浏览
  • qgb151 提出于 2023-12-18 17:02

相似问题