Pandas入门之 二:Series

已信任
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 for empty 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

 

posted @ 2021-07-12 22:06  vv_869  阅读(394)  评论(0编辑  收藏  举报