Pandas入門之 二:Series
阿新 • • 發佈:2021-07-12
已信任 Jupyter 伺服器: 本地 Python 3: Not Started import pandas as pd import numpy as np # pd.Series(data,index,dtype,copy) # data->資料,np.ndarry,list,constants # index->索引 # dtype:資料型別 # copy複製資料 s = pd.Series() s D:\Anaconda3\lib\site-packages\ipykernel_launcher.py:1: DeprecationWarning: The default dtype forempty Series will be 'object' instead of 'float64' in a future version. Specify a dtype explicitly to silence this warning. """Entry point for launching an IPython kernel. Series([], dtype: float64) data = np.array(['a','b','c','d']) s = pd.Series(data,index=[100,101,102,103]) s 100 a 101 b 102 c 103 d dtype: object # 字典建立Series data = { 'uesr1':100, 'uesr2':200, 'uesr3':250, } s = pd.Series(data) s uesr1 100 uesr2 200 uesr3 250 dtype: int64 # 標量建立Series s = pd.Series(5,index=[0,1,2,3]) s 0 5 1 5 2 5 3 5 dtype: int64 s = pd.Series([1,2,3,4,5,6], index=['a','b','c','d','e','f']) s a 1 b 2 c 3 d 4 e 5 f 6 dtype: int64
s[0] 1 s[0:3] a 1 b 2 c 3 dtype: int64 s[-3:] d 4 e 5 f 6 dtype: int64 s['a']# 通過標籤獲取數值 1 s[['a','c','f']]# 這裡要加2個[] a 1 c 3 f 6 dtype: int64