pandas一些基本操作(DataFram和Series)_3
2024-09-07 16:36:54
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 非空检测
最新文章
- Page Scroll Effects - 简单的页面滚动效果
- 《好设计不简单Ⅱ:UI设计师必须了解的那些事》
- JAVA基础知识之网络编程——-使用MutilcastSocket实现多点广播
- OpenResty 反向代理的用法与技巧
- git push 提示
- MySQL密码忘记之解决方法
- SQL SERVER 2008 架构
- 通信协议:HTTP、TCP、UDP(转)
- UVa 11879 - Multiple of 17
- Hadoop加zookeeper构建高可靠集群
- Unity 类似FingerGestures 的相机跟随功能
- layui框架部分功能介绍
- Linux 配置Jenkins
- xss框架基础框架实现
- 密码\路径\IP...备忘录
- cc1plus.exe: error: unrecognized command line option ";-fno-keep-inline-dllexport ";
- poj-2115-exgcd
- php array_rand()函数从数组中随机选择一个或多个元素
- 小峰mybatis(2)mybatis传入多个参数等..
- linux shell学习-1