python dataframe astype 字段类型转换
2016-08-17 13:59
585 查看
使用astype实现dataframe字段类型转换
输出结果:
注:data type list
# -*- coding: UTF-8 -*- import pandas as pd df = pd.DataFrame([{'col1':'a', 'col2':'1'}, {'col1':'b', 'col2':'2'}]) print df.dtypes df['col2'] = df['col2'].astype('int') print '-----------' print df.dtypes df['col2'] = df['col2'].astype('float64') print '-----------' print df.dtypes
输出结果:
col1 object col2 object dtype: object ----------- col1 object col2 int32 dtype: object ----------- col1 object col2 float64 dtype: object
注:data type list
Data type Description bool_ Boolean (True or False) stored as a byte int_ Default integer type (same as C long; normally either int64 or int32) intc Identical to C int (normally int32 or int64) intp Integer used for indexing (same as C ssize_t; normally either int32 or int64) int8 Byte (-128 to 127) int16 Integer (-32768 to 32767) int32 Integer (-2147483648 to 2147483647) int64 Integer (-9223372036854775808 to 9223372036854775807) uint8 Unsigned integer (0 to 255) uint16 Unsigned integer (0 to 65535) uint32 Unsigned integer (0 to 4294967295) uint64 Unsigned integer (0 to 18446744073709551615) float_ Shorthand for float64. float16 Half precision float: sign bit, 5 bits exponent, 10 bits mantissa float32 Single precision float: sign bit, 8 bits exponent, 23 bits mantissa float64 Double precision float: sign bit, 11 bits exponent, 52 bits mantissa complex_ Shorthand for complex128. complex64 Complex number, represented by two 32-bit floats (real and imaginary components) complex128 Complex number, represented by two 64-bit floats (real and imaginary components)
相关文章推荐
- python dataframe astype 字段类型转换方法
- python dataframe astype 字段类型转换
- Python DataFrame设置/更改列表字段/元素类型的方法
- TypeError: Error #1034: 强制转换类型失败:无法将 flash.display::BitmapData@79aea11 转换为 flash.display.Bitmap
- python pandas中series与dataframe数据类型属性及操作基础
- dataframe 存入MySQL,Python 'timestamp' cannot be converted to a MySQL type
- 请教:数据库字段类型为datatime,请问在.net里怎样转换为datetime类型来插入数据库?
- python 处理dataframe中的时间字段方法
- spark dataframe 类型转换
- python中创建dataframe数据,并将其转换成矩阵,对矩阵进行添加行列操作
- Python Numpy data-type dtype 自定义数据类型
- Java基本类型转换(Primitive Data Type Casting) int/byte & char
- 【Python 笔记】命名域之 TypeError 'DataFrame' object is not callable
- 如何将dataframe转换为rdd类型
- Python_pandas 两种主要的数据类型(Series、DataFrame)
- ADODB::_RecordSetPtr返回字段类型(ADODB::DataTypeEnum)说明
- MySQL笔记-MySQL支持的字段类型(dataType)
- python 处理dataframe中的时间字段
- Mybatis的数据库字段类型JDBCType和java基本数据类型转换说明
- R语言数据类型转换 List Vector Dataframe