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

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

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

 形式

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

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

Series是帶標(biāo)簽的一維數(shù)組,可存儲(chǔ)整數(shù)、浮點(diǎn)數(shù)、字符串、Python 對(duì)象等類(lèi)型的數(shù)據(jù),

軸標(biāo)簽統(tǒng)稱(chēng)為索引.。

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

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

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

import pandas as pd
#元組
print('元組')
tup=(1,2,3) # (元組)
s=pd.Series(tup)
print(s) # 不指定index, 則默認(rèn)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')
#由標(biāo)量創(chuàng)建
print('由標(biāo)量創(chuàng)建')
s=pd.Series(10)
print(s)
print('\n')
#指定index
print('指定index')
s=pd.Series("標(biāo)量",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)載請(qǐng)附上原文出處鏈接及本聲明。
原文鏈接: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


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


指定index
0    標(biāo)量
1    標(biāo)量
2    標(biāo)量
dtype: object

name, 給Series命名, 默認(rèn)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ù)類(lèi)型, 默認(rèn)dtype=None

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

結(jié)果: 

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

相關(guān)文章

最新評(píng)論