简体   繁体   English

将字符串数转换为在mongodb和python中浮动

[英]Convert string number to float in mongodb and python

I have a huge data in mongodb database and I want to figure out the data distribution such as min value, max value, average, and so on. 我在mongodb数据库中有大量数据,我想弄清楚最小值,最大值,平均值等数据分布。 My problem is the data type is string instead of integer or float so I can't sort the data, calculate the average etc. is there a way to convert datatype from string to float within pipeline? 我的问题是数据类型是字符串,而不是整数或浮点数,因此我无法对数据进行排序,计算平均值等。是否有一种方法可以将数据类型从字符串转换为浮点数? For example, to convert string date to date type, there is $dateFromString(aggregation) 例如,要将字符串日期转换为日期类型,请使用$ dateFromString(aggregation)

Or any other better idea to solve this problem? 或解决这个问题的其他更好的主意?

Since MongoDB is based off of Javascript, iirc, you can use the function 'parseFloat' to try to convert another data type to a float. 由于MongoDB基于Java iirc,因此可以使用函数'parseFloat'尝试将另一种数据类型转换为float。 There is also a 'parseInt' which tries to convert to an integer in case you need that. 还有一个“ parseInt”会在需要时尝试转换为整数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM