Pandas常見資料型別

2021-10-03 14:42:38 字數 2261 閱讀 2884

匯入

import pandas as pd

import numpy as p

建立series型別

np.series(data,index= ,dtype = )

data 可以是dict,array,list

# dict建立series

in [11]

: s = pd.series(

)in [12]

: sout[12]

:1122

23334dtype: int64

# list建立

in [14]

: se = pd.series([12

,23,34

],index=[1

,2,3

])in [15]

: se

out[15]

:1122

23334dtype: int64

#array建立

in [16]

: se = pd.series(np.array([12

,23,34

]),index=[1

,2,3

])in [15]

: se

out[15]

:1122

23334dtype: int64

series的一些方法和屬性:

#檢視形狀

in [19]

: se.shape

out[19]

:(3,

)#檢視index

in [21]

: se.index

out[21]

: int64index([1

,2,3

], dtype=

'int64'

)#檢視索引並把索引變成list

in [23]

: se.index.tolist(

)out[23]

:[1,

2,3]

#檢視維度

in [24]

: se.ndim

out[24]

:1#檢視值

in [27]

: se.values

out[27]

: array([12

,23,34

])#改變資料型別

in [26]

: se.astype(

float

)out[26]

:112.0

223.0

334.0

dtype: float64

#檢視資料型別

in [25]

: se.dtype

out[25]

: dtype(

'int32'

)#檢視有幾個元素

in [30]

: se.size

out[30]

:3

dataframe(data,index= ,coulmns = ,dtype= )

>>

> k = np.array([[

'小明'

,'男'],

['小蘭'

,'女'],

['小紅'

,'女']]

)>>

>> da = pd.dataframe(k,columns=

['姓名'

,'年齡'])

>>

>> da

姓名 年齡

0 小明 男

1 小蘭 女

2 小紅 女

# 利用列表

>>

> da = pd.dataframe([[

'小明'

,'男'],

['小蘭'

,'女'],

['小紅'

,'女']]

,columns=

['姓名'

,'年齡'])

>>

> da

姓名 年齡

0 小明 男

1 小蘭 女

2 小紅 女

# 利用字典

>>

> da = pd.dataframe(

)>>

> da

姓名 年齡

0 小明 男

1 小蘭 女

2 小紅 女

常見資料型別轉換

在最近兩個小專案中大量的使用了資料型別之間的互相轉換,因此寫一篇記述下來以便日後查閱。target 目標資料型別 需求資料型別 source 源資料型別 需轉換資料型別 string轉qstring target qstring fromstdstring source unsigned char ...

Windows常見資料型別

一,常見資料型別 word 16位無符號整形資料 dword 32位無符號整型資料 dword32 dword64 64位無符號整型資料 int 32位有符號整型資料型別 int ptr 指向int資料型別的指標型別 int32 32位符號整型 int64 64位符號整型 uint 無符號int l...

windows 常見資料型別

一,常見資料型別 word 16位無符號整形資料 dword 32位無符號整型資料 dword32 dword64 64位無符號整型資料 int 32位有符號整型資料型別 int ptr 指向int資料型別的指標型別 int32 32位符號整型 int64 64位符號整型 uint 無符號int l...