其他分享
首页 > 其他分享> > Series基本操作

Series基本操作

作者:互联网

1.Series中添加对象

import pandas as pd
dict1 = {"语文":91,"数学":90,"英语":89}
s1 = pd.Series(dict1)
s1.append(pd.Series({"高数":100,"物理":82}))

import pandas as pd
dict1 = {"语文":91,"数学":90,"英语":89}
s1 = pd.Series(dict1)
s1["化学"] = 65
s1["生物"] = 97
s1

2.获取Series索引(key)和值(value)

import pandas as pd
dict1 = {"语文":91,"数学":90,"英语":89}
s1 = pd.Series(dict1)
# 获取key
s1.index        # Index(['语文', '数学', '英语'], dtype='object')
# 获取value
s1.values       # array([91, 90, 89], dtype=int64)

3.指定Series索引

import pandas as pd
import numpy as np
s1 = pd.Series(np.arange(4),index = ["甲","乙","丙","丁"])
s1

4.检查Series是否为空

import pandas as pd
import numpy as np
dict1 = {"语文":91,"数学":np.nan,"英语":89}
s1 = pd.Series(dict1)
# 判断Series对象是否为空
s1.isnull()

 5.查看符合条件的Series

import pandas as pd
import numpy as np
dict1 = {"语文":91,"数学":86,"英语":89,"高数":97}
s1 = pd.Series(dict1)
# 找出成绩大于90分的科目
s1[s1>90]

标签:dict1,Series,s1,89,pd,import,基本操作
来源: https://blog.csdn.net/m0_60985598/article/details/123065518