网站被挂了黑链,猎头公司注册条件,中小企业网站建设如何,容易被收录的网站目录
0 总结
0.1pd.Dataframe有一个比较麻烦琐碎的地方#xff0c;就是引号 和括号
0.2 pd.Dataframe关于括号的原则
0.3 分清楚几个数据类型和对应的方法的范围
0.4 几个数据结构的构造关系
list → np.array(list) → pd.Series(np.array)/pd.Dataframe
1 python 里…目录
0 总结
0.1pd.Dataframe有一个比较麻烦琐碎的地方就是引号 和括号
0.2 pd.Dataframe关于括号的原则
0.3 分清楚几个数据类型和对应的方法的范围
0.4 几个数据结构的构造关系
list → np.array(list) → pd.Series(np.array)/pd.Dataframe
1 python 里的 pandas.Dataframe
2 pd.concat() 可以合并 pd.Dataframe
2.1 pd.concat() 合并规则
3 pd.Dataframe.drop() 删除行列的操作
4 pd.Dataframe 列操作
5 pd.Dataframe 行操作
5.1 sample_dataframe2.head(n2) 取前面的n行不能任意
5.2 sample_dataframe2.query(查询条件)取前面的n行不能任意
6 可以用pd.Dataframe().query() 方法 同时进行行和列筛选
7 序列 pandas.Series(
7.1 什么是序列
7.2 将pd.Dataframe取出1列会变成pd.Series
7.3 序列 pd.series 和数组array() 的转化 0 总结
0.1pd.Dataframe有一个比较麻烦琐碎的地方就是引号 和括号
用的比较多记住这个原则 pd.Dataframe所有的方法里基本都是加一个括起来基本就够了很少有多处多重引号的。 0.2 pd.Dataframe关于括号的原则
关于括号记住一个原则1层括号一般表示一维数组比如pd.Dataframe[]取出来的一般都是1列/1行等2层括号一般表示2维数组比如pd.Dataframe[[]] 取出来的一般都是一个子二维表有些地方需要多层的中括号[] 比如 [ [ ] ] 0.3 分清楚几个数据类型和对应的方法的范围
python原生的
原生类型列表listlist[1,2,3], 原生方法 range(1,10,1)
numpy和 pandas都是python的大包numpy里
对应的数据类型数组arrayarr1np.array([1,2,3])专有方法np.arange(1,10,1)np.arange(start1,stop10,step1) 0.4 几个数据结构的构造关系
list → np.array(list) → pd.Series(np.array)/pd.Dataframe
python原生的
列表listlist1[1,2,3],
numpy里
直接用列表生成np的数组array arr1np.array(list1)
pandas里
用 np.array 为内容直接生成pd.Seriespd.Series(np.array())用 np.array 为列生成pd.Dataframe({key1: np.array(),key2: np.array()})取出pd.Dataframe的某列生成pd.Seriespd.Series.values() np.array 1 python 里的 pandas.Dataframe
本质是一个二维表特殊点在于多了一个默认的序号列语法pd.Dataframe({key1:value1,key2:value2}) 2 pd.concat() 可以合并 pd.Dataframe
2.1 pd.concat() 合并规则
pd.concat() 语法pd.concat([pd.Dataframe1,pd.Dataframe1],axis0/1) pd.concat() 可以指定合并的方向默认是axis0也就是按行的方向合并pd.concat() 可以指定合并的方向如果是axis1就是按列的方向进行合并
import numpy as np
import pandas as pd
import scipy as sp# 可以用list 生成np.array()
sample_array1np.array([1,2,3])
sample_array2np.array([10,20,30])
sample_array3np.array([100,200,300])# 进一步可以用np.array()生成pd.Series
# 注意pd.Series 首字母一定大写
sample_series1pd.Series(sample_array1)
print(sample_series1)
print()# 进一步也可以用np.array()生成pd.DataFrame
# 注意pd.DataFrame 首字母一定大写
sample_dataframe1pd.DataFrame({col1:sample_array1,col2:sample_array2,col3:sample_array3,})
print(sample_dataframe1)
print()sample_dataframe2pd.DataFrame({col1:sample_array1,col2:sample_array21,col3:sample_array31,})
print(sample_dataframe2)
print()print(pd.concat([sample_dataframe1,sample_dataframe2])) # pd.concat()默认合并是axis0, 按行合并
print()print(pd.concat([sample_dataframe1,sample_dataframe2],axis1))
print() 3 pd.Dataframe.drop() 删除行列的操作
pd.Dataframe.drop()pd.Dataframe.drop(行名/列名,axis0/1)axis0 是行注意列名一般是字符串如 col1注意行名一般是数字如 1 4 pd.Dataframe 列操作
pd.Dataframe 数据帧操作列的办法有两种
直接引用 pd.Dataframe 对象的属性pd.Dataframe.列名不加字符串引号类切片的列操作方法pd.Dataframe[列名1]pd.Dataframe[[列名1,列名2,列名3]] #注意是双层中括号 5 pd.Dataframe 行操作
行操作有两种方法sample_dataframe2.head() 方法sample_dataframe2.query()方法 5.1 sample_dataframe2.head(n2) 取前面的n行不能任意
n 只能是前面的连续列
print(sample_dataframe2)
print()
print(sample_dataframe2.head(n2))5.2 sample_dataframe2.query(查询条件)取前面的n行不能任意
sample_dataframe2.query(查询条件)sample_dataframe2.query(可以是任意的一个行条件不要求非是index的值)sample_dataframe2.query(条件1 | 条件2) # or 关系sample_dataframe2.query(条件1 条件2) # and关系 6 可以用pd.Dataframe().query() 方法 同时进行行和列筛选 print(sample_dataframe2.query(col3301)[[col2,col3]]) 7 序列 pandas.Series( 7.1 什么是序列 特殊之处默认带一个序号列可以认为是带 序号的 数组/列表pandas.Series( data, index, dtype, copy) data输入的数据可以是列表、常量、ndarray 数组等。 index索引值必须是唯一的与data的长度相同默认为np.arange(n) dtype数据类型 copy是否复制数据默认为false 7.2 将pd.Dataframe取出1列会变成pd.Series
将pd.Dataframe取出1列会变成pd.Series也就是说 pd.Series 是 pd.Dataframe 的其中1列注意方法不同有差别如果是单取出1列生成pd.Series如果是单取出多列生成的只是更小的pd.Dataframe并不是pd.Series很好理解不要搞错。
print(sample_dataframe2)
print()
print(sample_dataframe2.col2)
print()
print(sample_dataframe2[col2])
print()
print(sample_dataframe2[[col2]])
print()print(type(sample_dataframe2))
print()
print(type(sample_dataframe2.col2))
print()
print(type(sample_dataframe2[col2]))
print()
print(type(sample_dataframe2[[col2]]))7.3 序列 pd.series 和数组array() 的转化
pd.series.values 即可以生成对应的 np.array() 数组
print(sample_dataframe2)
print()
print(sample_dataframe2.col2)
print()
print(sample_dataframe2.col2.values)
print()print(type(sample_dataframe2))
print()
print(type(sample_dataframe2.col2))
print()
print(type(sample_dataframe2.col2.values))
print()
文章转载自: http://www.morning.rjkfj.cn.gov.cn.rjkfj.cn http://www.morning.mqlsf.cn.gov.cn.mqlsf.cn http://www.morning.nyqnk.cn.gov.cn.nyqnk.cn http://www.morning.zcqbx.cn.gov.cn.zcqbx.cn http://www.morning.wrbx.cn.gov.cn.wrbx.cn http://www.morning.srmpc.cn.gov.cn.srmpc.cn http://www.morning.tslxr.cn.gov.cn.tslxr.cn http://www.morning.qykxj.cn.gov.cn.qykxj.cn http://www.morning.wfqcs.cn.gov.cn.wfqcs.cn http://www.morning.qcnk.cn.gov.cn.qcnk.cn http://www.morning.xqgtd.cn.gov.cn.xqgtd.cn http://www.morning.jkszt.cn.gov.cn.jkszt.cn http://www.morning.gxcit.com.gov.cn.gxcit.com http://www.morning.ckhyj.cn.gov.cn.ckhyj.cn http://www.morning.rjyd.cn.gov.cn.rjyd.cn http://www.morning.zsgbt.cn.gov.cn.zsgbt.cn http://www.morning.ylklr.cn.gov.cn.ylklr.cn http://www.morning.txqgd.cn.gov.cn.txqgd.cn http://www.morning.ssmhn.cn.gov.cn.ssmhn.cn http://www.morning.ctqlq.cn.gov.cn.ctqlq.cn http://www.morning.xqltq.cn.gov.cn.xqltq.cn http://www.morning.qjtbt.cn.gov.cn.qjtbt.cn http://www.morning.wjndl.cn.gov.cn.wjndl.cn http://www.morning.ymwcs.cn.gov.cn.ymwcs.cn http://www.morning.nfdty.cn.gov.cn.nfdty.cn http://www.morning.wqmyh.cn.gov.cn.wqmyh.cn http://www.morning.kbdrq.cn.gov.cn.kbdrq.cn http://www.morning.fmry.cn.gov.cn.fmry.cn http://www.morning.rmxgk.cn.gov.cn.rmxgk.cn http://www.morning.nytgk.cn.gov.cn.nytgk.cn http://www.morning.bppml.cn.gov.cn.bppml.cn http://www.morning.iknty.cn.gov.cn.iknty.cn http://www.morning.rlns.cn.gov.cn.rlns.cn http://www.morning.yskhj.cn.gov.cn.yskhj.cn http://www.morning.prqdr.cn.gov.cn.prqdr.cn http://www.morning.dpsyr.cn.gov.cn.dpsyr.cn http://www.morning.thlr.cn.gov.cn.thlr.cn http://www.morning.hxhrg.cn.gov.cn.hxhrg.cn http://www.morning.yqzyp.cn.gov.cn.yqzyp.cn http://www.morning.mtxrq.cn.gov.cn.mtxrq.cn http://www.morning.gccdr.cn.gov.cn.gccdr.cn http://www.morning.qrcxh.cn.gov.cn.qrcxh.cn http://www.morning.nchlk.cn.gov.cn.nchlk.cn http://www.morning.hsksm.cn.gov.cn.hsksm.cn http://www.morning.wmyqw.com.gov.cn.wmyqw.com http://www.morning.fbjqq.cn.gov.cn.fbjqq.cn http://www.morning.fchkc.cn.gov.cn.fchkc.cn http://www.morning.llthz.cn.gov.cn.llthz.cn http://www.morning.pqcbx.cn.gov.cn.pqcbx.cn http://www.morning.tzmjc.cn.gov.cn.tzmjc.cn http://www.morning.pnjsl.cn.gov.cn.pnjsl.cn http://www.morning.clybn.cn.gov.cn.clybn.cn http://www.morning.xuejitest.com.gov.cn.xuejitest.com http://www.morning.hphfy.cn.gov.cn.hphfy.cn http://www.morning.xclgf.cn.gov.cn.xclgf.cn http://www.morning.smdiaosu.com.gov.cn.smdiaosu.com http://www.morning.dsxgc.cn.gov.cn.dsxgc.cn http://www.morning.tyhfz.cn.gov.cn.tyhfz.cn http://www.morning.fllx.cn.gov.cn.fllx.cn http://www.morning.knnc.cn.gov.cn.knnc.cn http://www.morning.xbmwm.cn.gov.cn.xbmwm.cn http://www.morning.hhkzl.cn.gov.cn.hhkzl.cn http://www.morning.gcxfh.cn.gov.cn.gcxfh.cn http://www.morning.gxklx.cn.gov.cn.gxklx.cn http://www.morning.wpydf.cn.gov.cn.wpydf.cn http://www.morning.zqkr.cn.gov.cn.zqkr.cn http://www.morning.dwrbn.cn.gov.cn.dwrbn.cn http://www.morning.wkgyz.cn.gov.cn.wkgyz.cn http://www.morning.qdrrh.cn.gov.cn.qdrrh.cn http://www.morning.ngcbd.cn.gov.cn.ngcbd.cn http://www.morning.bhznl.cn.gov.cn.bhznl.cn http://www.morning.plqsz.cn.gov.cn.plqsz.cn http://www.morning.incmt.com.gov.cn.incmt.com http://www.morning.whothehellami.com.gov.cn.whothehellami.com http://www.morning.hlxxl.cn.gov.cn.hlxxl.cn http://www.morning.fwnqq.cn.gov.cn.fwnqq.cn http://www.morning.hrtct.cn.gov.cn.hrtct.cn http://www.morning.ggxbyhk.cn.gov.cn.ggxbyhk.cn http://www.morning.dhqyh.cn.gov.cn.dhqyh.cn http://www.morning.xcszl.cn.gov.cn.xcszl.cn