DataFrame中字段的型別判斷

2021-10-19 19:37:49 字數 1103 閱讀 4584

說明:如果某一列中有多種型別的資料,那麼會被識別為object。單單是str也是object

方法:dtype 或者 dtypes

直接上**吧

導包

import numpy as np

import pandas as pd

建立資料

型別輸出

data[

'y1'

].dtype

# dtype('int64')

data[

'y3'

].dtype

# dtype('float64')

data[

'y4'

].dtype

# dtype('o')

正確型別判斷

if data[

'y1'

].dtype is np.dtype(

'int64'):

print

('是int64型別'

)else

:print

('不是int64型別'

)# 是int64型別

錯誤型別判斷

if data[

'y1'

].dtype is

int:

print

('是int64型別'

)else

:print

('不是int64型別'

)# 不是int64型別

access中的字段型別

sql語句修改access中的字段型別 alter table tb alter column aa byte 數字 位元組 alter table tb alter column aa long 數字 長整型 alter table tb alter column aa short 數字 整型 a...

django中的字段型別

from charfield.max length 字元的最大長度,django會根據這個引數在資料庫層和校驗層限制該字段所允許的最大字元數。auto now 當物件被儲存時,自動將該字段的值設定為當前時間.通常用於表示 last modified 時間戳 auto now add 當物件首次被建立...

Pandas的DataFrame資料型別

pandas的dataframe資料型別 縱軸表示不同索引axis 0,橫軸表示不同列axis 1 dataframe型別建立 1.從二維ndarray物件建立 import pandas as pd import numpy as np d pd.dataframe np.arange 10 re...