Series数据类型

In  import pandas as pd
In  import numpy as np
In  S1=pd.Series()
In  S1
Out    Series([],dtype:float64)

 

In  S2=pd.Series([1,3,5,7,9],index=['a','b','c','d','e',])

Out    
a   1
b   3
c   5
d     7
e   9

dtype: int64

 

In  S2.values
Out    array([1,3,5,7,9],dtype=int64)
In  S2.index
Out    Index(['a','b','c','d','e'],dtype='object')

 

In  S2['f']=11
In  S2

Out    
a   1
b   3
c   5
d   7
e   9
f   11
dtype: int64

 

In  pd.Series({'a':1,'b':3,'c':5,'d':7})

Out    
a   1
b   3
c   5
d   7
dtype: int64

 

In  S3=pd.Series([1,3,-5,7])
In  S3

Out   
0   1
1   3
2   -5
3   7
dtype: int64

 

In  np.random.seed(54321)
In  pd.Series(np.random.randn(5))

Out   

0 0.223979
1 0.744591
2 -0.334269
3 1.389172
4 -2.296095
dtype: float64

 

In  pd.Series(np.arange(2,6))

Out   

0   2
1   3
2   4
3   5
dtype:int32

 

In  S4=pd.Series([0,np.NaN,2,4,6,8,True,10,12])
In  S4.head()

Out   

0   0
1   NaN
2   2
3   4
4   6
dtype:object

 

In  S4.head(3)

Out   

0   0
1   NaN
2   2
dtype:object

 

In  S4.tail()

Out   

4   6
5   8
6   True
7   10
8   12
dtype:object

 

In  S4.tail(6)

Out   

3   4
4   6
5   8
6   True
7   10
8   12
dtype:object

 

In  S4.take([2,4,0]) #指定索引值

Out   

2   2
4   6
0   0
dtype: object

 

In  S5=pd.Series([1,3,5,7,9],index=['a','b','c','d','e',])
In  S5[2],S5['d']

Out   

(5,7)

 

In  S5[[1,3,4]]

Out   

b   3
d   7
e   9

dtype: int64

 

In  S5[['b','e','d']]

Out   

b   3
d   7
e   9
dtype: int64

 

In  S5[0:4] #不包括结束位置

Out

a   2
b   4
c   6
d   8
dtype: int64

 

InS5['a':'d'] #包括结束位置

Out

a   1
b   3
c   5
d   7
dtype: int64

 

上一篇:查看Socket断开原因及加入心跳机制防止自动断开连接


下一篇:Go语言的学习之旅【五】