02 pandas Series 建立 屬性

2021-09-20 01:35:30 字數 3170 閱讀 8914

由一組資料和索引組成

資料是各種numpy資料型別

索引值可重複

# 使用 ndarray 建立

ran_num = np.random.randint(0,10,10)

print(ran_num)

# pd.series(data,dtype,index) 資料,資料型別,定義索引

pd.series(ran_num)

print(pd.series(ran_num,dtype="float32",index=list('abcdefghij')))

[1 6 9 1 8 2 9 4 8 9]

a 1.0 b 6.0 c 9.0 d 1.0 e 8.0 f 2.0 g 9.0 h 4.0 i 8.0 j 9.0 dtype: float32

# 使用列表建立

scores = [90,100,33]

pd.series(scores,index=["語文","數學","英語"])

語文 90 數學 100 英語 33 dtype: int64

#使用字典建立,字典key會用作索引

scores=

pd.series(scores)

數學 88 英語 100 語文 90 dtype: int64

注意:字典是無序的,所以輸出的內容順序不一

print('-'*10+'ser_scores'+'-'*10)

ser_scores = pd.series(scores)

print(ser_scores)

print('-'*12+'取索引'+'-'*12)

# 取索引

print(ser_scores.index)

print(ser_scores.axes)

print('-'*12+'取值'+'-'*12)

#取值print(ser_scores.values)

print('-'*12+'取型別'+'-'*12)

#取型別

print(ser_scores.dtype)

print('-'*12+'檢視維度'+'-'*12)

# 檢視維度 ndim

print(ser_scores.ndim)

print('-'*10+'檢視元素個數'+'-'*10)

# 檢視元素個數 size

print(ser_scores.size)

print('-'*10+'檢視前2條資料'+'-'*10)

# 前兩行 head

print(ser_scores.head(2))

print('-'*10+'檢視後2條資料'+'-'*10)

# 後兩行 tail

print(ser_scores.tail(2))

# 排序

print('-'*12+'公升序排序'+'-'*12)

#公升序print(ser_scores.sort_values())

print('-'*12+'降序排序'+'-'*12)

#降序print(ser_scores.sort_values(ascending=false))

----------ser_scores----------

----------ser_scores----------

數學 88

英語 100

語文 90

dtype: int64

------------取索引------------

index(['數學', '英語', '語文'], dtype='object')

[index(['數學', '英語', '語文'], dtype='object')]

------------取值------------

[ 88 100 90]

------------取型別------------

int64

------------檢視維度------------

1----------檢視元素個數----------

3----------檢視前2條資料----------

數學 88

英語 100

dtype: int64

----------檢視後2條資料----------

英語 100

語文 90

dtype: int64

------------公升序排序------------

數學 88

語文 90

英語 100

dtype: int64

------------降序排序------------

英語 100

語文 90

數學 88

dtype: int64

print('-'*12+'給series設定名字'+'-'*12)

#給series設定名字

ser_scores.name="tom的成績"

print(ser_scores)

print('-'*12+'給index設定名字'+'-'*12)

#給index設定名字

ser_scores.index.name="課程"

print(ser_scores)

------------給series設定名字------------

課程數學 88

英語 100

語文 90

name: tom的成績, dtype: int64

------------給index設定名字------------

課程數學 88

英語 100

語文 90

name: tom的成績, dtype: int64

# 檢視series是否為空

if(ser_scores.empty == false):

print('不為空')

建立lucene時document欄位屬性的選擇

在建立索引檔案的時候,不知道會不會有下面的疑惑 1 document欄位設定成什麼型別?2 採用什麼分詞器?3 欄位的權重設定成多少等?這些也許都是我們在建立索引檔案中經常會遇到的問題,這篇就主要說一下自己關於第乙個問題的理解 此篇是以 lucene 4.3.1 為事例,其他版本類似 個人認為,我們...

02 建立執行緒方式

extends thread 非實現變數共享 public class mythread extends thread override public void run 使用extends thread 建立3個執行緒 即建立3個mythread例項物件 每個執行緒都有各自的count變數,自己減少...

React學習 02建立

執行npm init y快速初始化專案 在專案根目錄建立src源 目錄和dist產品目錄 在 src 目錄下建立index.html使用 cnpm 安裝 webpack 執行cnpm i webpack webpack cli d注意 webpack 4.x 提供了 約定大於配置的概念 目的是為了儘...