最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python dataframe astype 字段類型轉(zhuǎn)換方法

 更新時間:2018年04月11日 09:53:38   作者:伴生伴熟  
下面小編就為大家分享一篇python dataframe astype 字段類型轉(zhuǎn)換方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

使用astype實現(xiàn)dataframe字段類型轉(zhuǎn)換

# -*- 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

輸出結(jié)果:

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 字段類型轉(zhuǎn)換方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

许昌县| 巴里| 盘锦市| 新巴尔虎左旗| 乌恰县| 龙南县| 灌南县| 灌南县| 民丰县| 冷水江市| 株洲县| 连平县| 昆山市| 玛纳斯县| 上犹县| 拉萨市| 湖北省| 景洪市| 高碑店市| 肥城市| 通州区| 仙居县| 南乐县| 平原县| 平邑县| 桑植县| 云阳县| 高要市| 邹城市| 邛崃市| 繁昌县| 杨浦区| 彩票| 阳朔县| 新兴县| 东至县| 乌什县| 萍乡市| 海宁市| 清涧县| 讷河市|