标签:chinese scores name 维数 通过 数组 core random match
import pandas as pd;
import numpy as np
#通过一维数组创建
Chinese = np.array([89,87,86])
print(Chinese)
print(pd.Series(Chinese))
print(pd.Series(Chinese,index=[‘xiaoming‘,‘xiaohong‘,‘xiaohei‘],dtype=‘float‘))
#通过字典创建
Chinese2={"小红":98,"小黑":76,"小王":65}
score = pd.Series(Chinese2)
print(score)
print(score.index)
abc = score.index=list(‘abc‘)#修改索引值
print("====================================")
print(score.values)
#设置数据变量名
score.name=‘语文‘
score.index.name=‘姓名‘
print(score)
#axes 获取索引
print(score.axes)
print(score.index)
#empty 是否为空
print(score.empty)
#head tail 返回前几行 返回后几行
scores = pd.Series(np.random.randint(60,100,20));
print(scores)
print(scores.head(3))
#p排序 取前几名
print(scores.sort_values(ascending=False).head(3))
#Series值获取 索引值可以重复
ser1 = pd.Series([33,22,55,72,63],index=list(‘abcde‘));
print(ser1)
print(ser1[‘c‘])#index取值
print(ser1[3])#下表取值
print(ser1[‘b‘:‘d‘])#切片 索引切片是包含末尾的
print(ser1[1:4])#下表切片 不包含末尾
#!!如果重复index 利用这个重复值去切片就会报错
#Series运算
print(Chinese)
Chinese_ser1 = pd.Series(Chinese)
Chinese_ser1.index = [‘小红‘,‘小黑‘,‘小王‘]
print(Chinese_ser1)
Match_ser1 = pd.Series({"小红":88,"小黑":99,"小王":70,"海涛":"1"})
total_ser1 = Match_ser1 + Chinese_ser1
print(total_ser1) #np是依赖位置相加,Series是根据index去相加的(自动对齐)
#缺失值检测
print(total_ser1.isnull())#notnull 非空检测
pandas一些基本操作(DataFram和Series)_3
标签:chinese scores name 维数 通过 数组 core random match
原文地址:https://www.cnblogs.com/yaohaitao/p/10296739.html