ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Series数据类型

2021-02-19 14:32:45  阅读:447  来源: 互联网

标签:Series 数据类型 S5 int64 pd dtype Out


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

 

标签:Series,数据类型,S5,int64,pd,dtype,Out
来源: https://www.cnblogs.com/jackie-ding/p/14415940.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有