本文摘自php中文网,作者php中世界最好的语言,侵删。
这次给大家带来object格式怎样无损转换成float64格式,object格式无损转换成float64格式的注意事项有哪些,下面就是实战案例,一起来看一下。在数据处理过程中
比如从CSV文件中导入数据
1 | data_df = pd.read_csv( "names.csv" )
|
在处理之前一定要查看数据的类型
1 2 3 4 5 6 7 8 9 10 11 12 13 | *RangeIndex: 891 entries, 0 to 890
Data columns (total 12 columns):
Name 891 non-null object
Sex 891 non-null object
Age 714 non-null float64
SibSp 891 non-null int64
Parch 891 non-null int64
Ticket 891 non-null object
Fare 891 non-null float64
Cabin 204 non-null object
Embarked 889 non-null object
dtypes: float64(2), int64(5), object(5)
memory usage: 83.6+ KB*
|
以上object , int64, 以及 float64 便是数据的类型。
如果我们需要对列数据进行相互之间的运算的吧,必须注意的一点是:
两列的数据类型是否是相同的!!
如果一个object类型与int64的类型相加,便会发生错误
错误提示可能如下:
1 | TypeError: ufunc 'add' not contain a loop with signature matching types dtype( '<U32' ) dtype( '<U32' ) dtype( '<U32' )
|
此时的object类型可能是‘12.3'这样str格式的数字,如果要运算必须进行格式转换:
可采用如下方法(convert_objects):
1 | dt_df = dt_df.convert_objects(convert_numeric=True)
|
亲测有效。
再提醒一遍!得到数据一定要先查看数据类型!!!
相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
推荐阅读:
object怎么转换成float数据
Vue2父组件与子组件的双向绑定怎么实现
以上就是object格式怎样无损转换成float64格式的详细内容,更多文章请关注木庄网络博客!!
相关阅读 >>
Python中的numpy是什么
ipad 能做Python开发吗
9种Python web程序的部署方式小结
Python绝对值怎么计算
range函数Python2和3区别
如何卸载Python3.5
Python为什么适合人工智能
什么是Python中的协程?(实例解析)
在cmd中Python如何卸载模块
numpy中实现ndarray数组返回符合特定条件的索引方法
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » object格式怎样无损转换成float64格式