欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python中pd.Series()函數(shù)的使用

 更新時間:2023年05月16日 10:51:31   作者:小小白2333  
本文主要介紹了python中pd.Series()函數(shù)的使用,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

 形式

pandas.Series(data=None,?index=None,?dtype=None,?name=None,?copy=False,?fastpath=False)

Pandas 主要的數(shù)據(jù)結(jié)構(gòu)是 Series(一維)與 DataFrame(二維) 

Series是帶標簽的一維數(shù)組,可存儲整數(shù)、浮點數(shù)、字符串、Python 對象等類型的數(shù)據(jù),

軸標簽統(tǒng)稱為索引.。

Pandas會默然用0到n-1來作為series的index,但也可以自己指定index(可以把index理解為dict里面的key)。

調(diào)用 pd.Series 函數(shù)即可創(chuàng)建 Series:

由(元組),[列表],一維數(shù)組,字典,標量創(chuàng)建

import pandas as pd
#元組
print('元組')
tup=(1,2,3) # (元組)
s=pd.Series(tup)
print(s) # 不指定index, 則默認index為[0,1,len(s)-1]
print('\n')
#列表
print('列表')
lst=[1,2,3] # [列表]
s=pd.Series(lst)
print(s)
print('\n')
# 一維數(shù)組
import numpy as np
print('一維數(shù)組')
arr=np.array([1,2,3]) # 一維數(shù)組
s=pd.Series(arr)
print(s)
print('\n')
#由{字典}創(chuàng)建
print('字典')
dic={"index0":1,"index1":2,"index2":3} # {字典}
s=pd.Series(dic)
print(s)
print('\n')
#由標量創(chuàng)建
print('由標量創(chuàng)建')
s=pd.Series(10)
print(s)
print('\n')
#指定index
print('指定index')
s=pd.Series("標量",index=range(3))#指定index為[0,1,2]
print(s)
————————————————
版權(quán)聲明:本文為CSDN博主「小小白2333」的原創(chuàng)文章,遵循CC 4.0 BY-SA版權(quán)協(xié)議,轉(zhuǎn)載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/Ajdidfj/article/details/123063958

結(jié)果:

元組
0    1
1    2
2    3
dtype: int64


列表
0    1
1    2
2    3
dtype: int64


一維數(shù)組
0    1
1    2
2    3
dtype: int32


字典
index0    1
index1    2
index2    3
dtype: int64


由標量創(chuàng)建
0    10
dtype: int64


指定index
0    標量
1    標量
2    標量
dtype: object

name, 給Series命名, 默認name=None

import pandas as pd?
lst=[1,2,3]
s=pd.Series(lst,name="aaa") # 給Series命名為"aaa"
print(s)??

結(jié)果: 

dtype, 給Series里的成員指定數(shù)據(jù)類型, 默認dtype=None

import numpy as np
import pandas as pd
lst=[1,2,3]
s=pd.Series(lst,dtype=np.float64) # 指定數(shù)據(jù)類型為np.float64
print(s)?

結(jié)果: 

到此這篇關于python中pd.Series()函數(shù)的使用的文章就介紹到這了,更多相關python pd.Series()內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

最新評論