pandas(莫烦python)学习笔记

pandas基本介绍

pandas.Series([…]) #创建序列
pandas.date_range(‘20200729’,periods=7)# 创建日期序列
pandas.DataFrame(…,index=…,columns=…)# 创建制定索引矩阵
A.index#行索引名称
A.columns#列索引名称
A.values#矩阵值
A.describe()#描述矩阵
A.T# 反相矩阵
A.sort_index(axis=1,ascending=False)# 按列倒序排序
A.sort_values(by=’…’)#对值排序

pandas选择数据

A[‘a’] or A.a#选择指定列值
A[…:…]#选择指定行的值
A.loc[’…’,’…’]#以标签来选择值
A.iloc[…,…]#以位置来选择值
A[A.a>1]#以a列数值大于1值来筛选值

pandas设置值

A.iloc[…,…] = 111#以位置来改
A.loc[’…’,’…’] = 111#以标签来改
A[A.a>1] = 0#以列筛选数值对矩阵全部修改
A.a[A.a>1] = 0#仅对制定列筛选值修改

pandas处理丢失数据

A.dropna(axis=0,how=‘any’) how={‘any’,‘all’}#删掉缺失数据所在的一行
A.fillna(value=0)#将所有缺失数据改为0
A.isnull#判断是否存在缺失数据
numpy.any(A.isnull())==True#大数据中判断是否存在数据丢失

pandas导入导出

#可以读取的格式
read_csv
read_excel
read_hdf
read_sql
read_json
read_msgpack(experimental)
read_html
read_gbq(experimental)
read_stata
read_sas
read_clipboard
read_pickle
#保存格式
to_csv
to_excel
to_hdf
to_sql
to_json
to_msgpack(experimental)
to_html
to_gbq(experimental)
to_stata
to_sas
to_clipboard
to_pickle

pandas合并concat

pandas.concat([A,B,C],axis=1)#左右合并
pandas.concat([A,B,C],axis=0,ignore_index=True)#上下合并并重新生成索引
pandas.concat([A,B,C],join=‘inner’)#默认join=outer并集而inner为交集
A.append(B)#逐行添加

pandas合并merge

pandas.merge(A,B,on=’…’)#按照某列索引合并
pandas.merge(A,B,on=[’…’,’…’],how=‘inner’)#默认inner交集还有outer并集right以B索引为基准left以A索引为基准
pandas.merge(A,B,on=[’…’,’…’],how=‘outer’,indicator=True) #显示合并方式
pandas.merge(A,B,left_index=True,right_index=True,how=‘outer’) #按照行索引合并
pandas.merge(A,B,on=’…’,suffixes=[’…’,’…’],how=‘outer’) #增加行索引后缀

pandas plot图表

import matplotlib.pyplot as plt #显示数据模块
A.plot()
plt.show()#显示图表
A.plot.scatter()
plt.show()#散点图
还有’bar’,‘hist’,‘box’,‘kde’,ares’,‘hexbin’,‘pie’

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值