首页 > 编程知识 正文

numpy数据类型转换,python将字符转化为日期

时间:2023-05-06 21:05:33 阅读:28637 作者:1371

使用astype进行数据帧字段类型转换#-- *--编码: utf-8-- * -

导入pandas as PD

df=PD.dataframe({'col1':'a '、' col2':'1'}、{'col1':'b '、' col2'3360'2'} )

print df.dtypes

df [ ' col2' ]=df [ ' col2' ].as type (' int ' )

print '-----------'

print df.dtypes

df [ ' col2' ]=df [ ' col2' ].as type [ ' float 64 ' ]

print '-----------'

print df.dtypes

输出结果: col1 object

col 2对象

dtype :对象

------------

col 1对象

col2 int32

dtype :对象

------------

col 1对象

Col 2浮点64

dtype :对象

注: datatypelistdatatypedescription

bool_boolean(trueorfalse ) stored as a byte

int _ defaultintegertype (sameasclong; normally either int64 or int32 )

intcidenticaltocint (正规int 32 orint 64 ) )。

intpintegerusedforindexing (sameascssize _ t; normally either int32 or int64 )

int 8字节(-128 to 127 ) )。

int16integer(-32768to32767 )。

int 32 integer (-2147483648 to 2147483647 )。

int 64 integer (-922372036854775808 to 922337203685475807 () )。

uint 8统一整合器(0to255 )。

uint 16统一整合器(0to 65535 )。

uint 32无信号集成器(0to 4294967295 )。

uint 64 unsigned integer (0to 18446744073709551615 )

float_ Shorthand for float64。

float 16半流程浮点: signbit,5 bits exponent,10 bits mantissa

浮动32 singleprecisionfloat : signbit,8 bits exponent,23 bits mantissa

浮点64双精度浮点: signbit,11 bits exponent,52 bits mantissa

complex_ Shorthand for complex128。

complex64 Complex number,representedbytwo32-bitfloats,realandimaginarycomponents )

complex128 Complex number,representedbytwo 64位浮动,realandimaginarycomponents )

以上python dataframe astype字段的类型转换方法是编辑共享给大家的所有内容。 希望能作为参考。 另外,我希望你多支持聚米学院。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。