pandas(三)

score=pd.read_csv("./file.csv",names=[‘classes’,‘stuid’,‘C’,“M”,“E”])
在这里插入图片描述
1 score[‘classes’].unique()
unique 去重 返回不同的值
2 score[‘classes’].value_counts()
值计数 从大到小排序
3 score[‘classes’].isin([‘AI11’,‘AI12’])
判断 classes里的成员是否是AI11 、AI12
4 data.swaplevel().sort_index(level=0)
交换索引 swaplevel()
5 df1=data.unstack(level=1)
unstack 转换为DataFrame level 写成等于哪一列,哪一列就作为DataFrame的列索引
6 score.sort_index(axis=1,ascending=True)
对DataFrame 按索引的大小进行排序,axis=1 按列索引进行排序,axis=0 按行索引进行排序
7 ser1=pd.Series([89,89,54,100,33])
ser1.rank(ascending=False,method=“first”)
rank排序 返回最大值的索引
8 g_data=pd.read_csv("./file.csv",names=[‘id’,‘value’],index_col=0)
names=[‘id’,‘value’] 添加列索引
index_col=0 指定第一列为索引 index_col=1 指定第二列为索引
9 date_range(start,end,freq,periods) 生成时间序列
start end 开始时间和结束时间 freq 每隔多久生成一个时间点 S 秒数 D 天 H 小时 T 分钟 M 月份 Y 年
g_index=pd.date_range(start=“1970/11/10 08:00:00”,freq=“Y”,end=“2019/11/10 10:00:00”)

表合并

pd.merge(data1,data2,left_on,right_on,on,left_index,right_index,how)
left_on right_on 左右表以哪个字段连接
on 如果两个表中 要连接的字段名是相同的,使用 on 或者不写
left_index right_index 当两个表中的连接字段是索引时 设置 left right _index为True
how 表连接的方式 默认为 inner 交集 outer 并集
**
stu_info=pd.read_csv("./file/merge_stu_name.csv")
stu_score=pd.read_csv("./file/merge_stu_score.csv")**
10 data3=pd.merge(stu_info,stu_score,on=‘stu_id’)
表一和表二同过共同的列 ‘stu_id’ 进行合并
11 data3=pd.merge(stu_info,stu_score,left_index=True,right_index=True,how=“inner”)

concat 堆叠

12 pd.concat((stu_info,stu_info2),sort=False,join=‘inner’,axis=1)
join 表连接的方式 默认为 inner 交集 outer 并集
上下堆叠,列相加

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值