世界杯视频直播网站推荐,网络认证网站,产品画册,做国外网站汇款用途是什么pandas的数据加载与预处理
数据清洗#xff1a;洗掉脏数据 整理分析#xff1a;字不如表 数据展现#xff1a;表不如图 环境搭建
pythonjupyter anaconda Jupyter Notebook Jupyter Notebook可以在网页页面中直接编写代码和运行代码, 代码的运行结果也会直接在代码块下显示…pandas的数据加载与预处理
数据清洗洗掉脏数据 整理分析字不如表 数据展现表不如图 环境搭建
pythonjupyter anaconda Jupyter Notebook Jupyter Notebook可以在网页页面中直接编写代码和运行代码, 代码的运行结果也会直接在代码块下显示的程序。
整合所有的资源 交互性编程体验 零成本重现结果(云运行/在线运行) 运行方法 任意目录打开终端输入
jupyter-notebook 定义端口
jupyter-notebook -port 8899 更换目录
jupyter notebook -generate-config
数据加载与存储 常见格式存储
import pandas as pd
pd.read_excel() # 从exce1的.xls或.xlsx格式读取表格数据 pd.read_csv()#从csv文件读取数据 pd.read_table() # 从txt文件读取数据 pd.read_sq1( )#将sql查询的结果(使用SQLAlchemy) 读取为pandas的DataF rame pd.read_html( )#读取网页中的表格数据 pd. read_json( )#从json字符串中读取数据 pd.read_xml#从xml文件中读取数据 …………………………………………等等
格式转换
datapd.read_excel(./1.xlsx) data.to_csv(./1.csv)
pandas两大数据结构
Series一维数据列
DataFrame多维数据
常用函数
data. shape #数据维度看看数据多少行多少列 data . head(3) #检查头数据 data. info() #查看数据基本信息 data. dtypes #查看数据类型 data . describe( ) #查看数值数据统计信息
描述性统计分析
data[‘省份’]. unique #显示某列所有的唯一值 data[‘省份’].value_ counts() #返回每个元素有多少个 data[‘收益(元) ’ ] . idxmax() #返回最大值所在索引 data .nlargest(3,‘收益(元)’) #返回前几个大的元素值所在行 data. sort_ values (by’’ ,ascending‘’) #根据某一列进行排序
查看指定多行、列、行列
data. columns. tolist( ) data[1:5] data[[’ ip’ ,’ phone’ ] ] data.loc[ ] data. iloc [] 方法名称 参数 说明 边界 .loc[] [row,columns] 基于标签索引选取数据 前闭后闭 .iloc[] [row,columns] 基于整数索引选取数据 前闭后开
缺失值检查与处理
缺失数据查看和修改
data[ data. isnull().values] #查看缺失值 data.dropna() #删除缺失值 data.fillna() #填充缺失值
缺失数据高亮
#某网站会员收益表.xlsx data.isna().sum().sum() #检查全部缺失值总数 data.isnull().sum( ) #检查每列缺失值 #将缺失值进行高亮 (data[data.isnull().any(1) True] style .highlight_null(nu11_color‘skyblue’) .set_table_attributes( ‘style“font-size: 10px”’))
#填充固定值 datal data.fillna( data1 #向下填充 data2 data. fillna(method‘bfill’) data2
#均值填充
data3 data[‘收益(元)’ ].fillna(data[‘收益(元)’] .mean()) data3. map(lambda cell:‘%.2f’ % cel1)
#大多数时候我们是从csv文件中导入的数据此时Dataframe中对应的时间列是字符串或时间戳的形式
type(user[‘create_ time’ ][1])
#运用pd.to_ datetime().可以将对应的列转换为Pandas中的datetime64类型便于后期的处理 user[ ‘create time’] pd.to datetime(user[‘create_time’ ],unit‘s’) user[‘create_time’] user[‘create_time’].map(lambda x : pd.to_datetime(x,unit‘s’)) type(user[create_ time ][1]) #时间序列的索引。和普通索引一样调用.1oc[row, columns ]进行索引 user1 user .set_ index(‘create_time’ ) user1.1oc[‘2022-05’]
2022年5月 -2022年7月的数据
user1.1oc[ ’ 2022-05’: ‘2022-07’] user[ create time’ ].dt.month
重复值检查与处理
data[data.duplicated()] #筛选重复值所在行 data[data.duplicated([‘姓名’])] #筛选指定列. data.drop_duplicates() #删除重复值所在行
数据修改与筛选
#修改列名 df . rename( columns{ ‘姓名’:‘中文名字’ ‘city’ : ’ birthday ’ }) #修改素引所在行 df.set_ index( ‘id’inplaceTrue ) df.reset index(inplaceTrue) df.drop([’ index’ ]) #修改索引名字 df.rename axis(’ 自加素引’) #修改某一个值 df.iloc[0,1]‘林1’ #替换指定的值 df.replace(3, 0, inplaceTrue ) df.replace(0,3, inplaceTrue) df.replace(‘林永玲’ ,3, inplaceTrue ) df.iloc[0,1]‘林永玲’ df.head(10) df.drop(1)#删除指定行
df.drop(df[df[‘收益(元)’ ]10000] . index)#删除条件行
df.drop(columns[ ‘省份’], inplaceTrue )#删除列
df.drop(df.columns[[6,7,8]], axis1, inplaceTrue )#删除列按列号
其它分析工具
OpenRefine
IBM i2 文章转载自: http://www.morning.ywpwg.cn.gov.cn.ywpwg.cn http://www.morning.pbmkh.cn.gov.cn.pbmkh.cn http://www.morning.rjnrf.cn.gov.cn.rjnrf.cn http://www.morning.jftl.cn.gov.cn.jftl.cn http://www.morning.cwyrp.cn.gov.cn.cwyrp.cn http://www.morning.xrpwk.cn.gov.cn.xrpwk.cn http://www.morning.bgbnc.cn.gov.cn.bgbnc.cn http://www.morning.lwmxk.cn.gov.cn.lwmxk.cn http://www.morning.fhhry.cn.gov.cn.fhhry.cn http://www.morning.yhwmg.cn.gov.cn.yhwmg.cn http://www.morning.jtfcd.cn.gov.cn.jtfcd.cn http://www.morning.zbjfq.cn.gov.cn.zbjfq.cn http://www.morning.sgpny.cn.gov.cn.sgpny.cn http://www.morning.dcpbk.cn.gov.cn.dcpbk.cn http://www.morning.hmktd.cn.gov.cn.hmktd.cn http://www.morning.yhglt.cn.gov.cn.yhglt.cn http://www.morning.cgmzt.cn.gov.cn.cgmzt.cn http://www.morning.bxnrx.cn.gov.cn.bxnrx.cn http://www.morning.sloxdub.cn.gov.cn.sloxdub.cn http://www.morning.tzpqc.cn.gov.cn.tzpqc.cn http://www.morning.flxqm.cn.gov.cn.flxqm.cn http://www.morning.btqqh.cn.gov.cn.btqqh.cn http://www.morning.wnbqy.cn.gov.cn.wnbqy.cn http://www.morning.yqhdy.cn.gov.cn.yqhdy.cn http://www.morning.ksggl.cn.gov.cn.ksggl.cn http://www.morning.rfyff.cn.gov.cn.rfyff.cn http://www.morning.ydmml.cn.gov.cn.ydmml.cn http://www.morning.sthgm.cn.gov.cn.sthgm.cn http://www.morning.gnlyq.cn.gov.cn.gnlyq.cn http://www.morning.mypxm.com.gov.cn.mypxm.com http://www.morning.dkzrs.cn.gov.cn.dkzrs.cn http://www.morning.jfbpf.cn.gov.cn.jfbpf.cn http://www.morning.dmtwz.cn.gov.cn.dmtwz.cn http://www.morning.qyhcg.cn.gov.cn.qyhcg.cn http://www.morning.krzrg.cn.gov.cn.krzrg.cn http://www.morning.mrttc.cn.gov.cn.mrttc.cn http://www.morning.jqbmj.cn.gov.cn.jqbmj.cn http://www.morning.nwjd.cn.gov.cn.nwjd.cn http://www.morning.dmwbs.cn.gov.cn.dmwbs.cn http://www.morning.byxs.cn.gov.cn.byxs.cn http://www.morning.jmtrq.cn.gov.cn.jmtrq.cn http://www.morning.jzlfq.cn.gov.cn.jzlfq.cn http://www.morning.ypwlb.cn.gov.cn.ypwlb.cn http://www.morning.yhgbd.cn.gov.cn.yhgbd.cn http://www.morning.rqpgk.cn.gov.cn.rqpgk.cn http://www.morning.brld.cn.gov.cn.brld.cn http://www.morning.gfqjf.cn.gov.cn.gfqjf.cn http://www.morning.nndbz.cn.gov.cn.nndbz.cn http://www.morning.sqdjn.cn.gov.cn.sqdjn.cn http://www.morning.rnfwx.cn.gov.cn.rnfwx.cn http://www.morning.knryp.cn.gov.cn.knryp.cn http://www.morning.yrngx.cn.gov.cn.yrngx.cn http://www.morning.wsrcy.cn.gov.cn.wsrcy.cn http://www.morning.zhishizf.cn.gov.cn.zhishizf.cn http://www.morning.nfqyk.cn.gov.cn.nfqyk.cn http://www.morning.bbgn.cn.gov.cn.bbgn.cn http://www.morning.hbkkc.cn.gov.cn.hbkkc.cn http://www.morning.qgjxt.cn.gov.cn.qgjxt.cn http://www.morning.jwdys.cn.gov.cn.jwdys.cn http://www.morning.yrpg.cn.gov.cn.yrpg.cn http://www.morning.jmnfh.cn.gov.cn.jmnfh.cn http://www.morning.guanszz.com.gov.cn.guanszz.com http://www.morning.znqmh.cn.gov.cn.znqmh.cn http://www.morning.tpmnq.cn.gov.cn.tpmnq.cn http://www.morning.ypcd.cn.gov.cn.ypcd.cn http://www.morning.lwrks.cn.gov.cn.lwrks.cn http://www.morning.ybmp.cn.gov.cn.ybmp.cn http://www.morning.rwlns.cn.gov.cn.rwlns.cn http://www.morning.bwttj.cn.gov.cn.bwttj.cn http://www.morning.qzzmc.cn.gov.cn.qzzmc.cn http://www.morning.fchkc.cn.gov.cn.fchkc.cn http://www.morning.qmncj.cn.gov.cn.qmncj.cn http://www.morning.rtzd.cn.gov.cn.rtzd.cn http://www.morning.hwlmy.cn.gov.cn.hwlmy.cn http://www.morning.prplf.cn.gov.cn.prplf.cn http://www.morning.slfmp.cn.gov.cn.slfmp.cn http://www.morning.ntdzjx.com.gov.cn.ntdzjx.com http://www.morning.tmlhh.cn.gov.cn.tmlhh.cn http://www.morning.qypjk.cn.gov.cn.qypjk.cn http://www.morning.kmqms.cn.gov.cn.kmqms.cn