随笔分类 -  数据分析

摘要:合并 merge,concat,join pd.merge(df1,df2,on=‘列名’,how='') df1.join(df2,how='outer',on='') pd.concat([df1,df2],join='outer') 去重 drop_duplicates df1.drop_du 阅读全文
posted @ 2019-06-18 18:29 saber丶吾王 阅读(203) 评论(0) 推荐(0)
摘要:合并数据集: 创建一个能创建dataframe的函数 def make_data(cols,ind): data={c:[strc(c)+str(i) for i in ind] for c in cols} return pd.DataFrame(data,ind) make_data('ABC' 阅读全文
posted @ 2019-04-02 17:22 saber丶吾王 阅读(202) 评论(0) 推荐(0)
摘要:层级索引: index=[('a',2010),('b',2011),('c',2010'),('a',2012),('e',2010),('f',2011)] age=[18,17,18,16,18,17] 常规创建 pop =pd.Series(age,index=index) MultiInd 阅读全文
posted @ 2019-04-02 15:32 saber丶吾王 阅读(207) 评论(0) 推荐(0)
摘要:import numpy as py import pandas as pd Series对象 data= pd.Series([0.25,0.5,0.75,1.0]) 默认索引是数字 data=pd.Series([0.25,0.5,0.75,1.0],index=['a','b','c','d' 阅读全文
posted @ 2019-04-02 12:04 saber丶吾王 阅读(290) 评论(0) 推荐(0)
摘要:排序: x=np.array([2,5,6,2,3,5]) np.sort(x) 不改变原数组 x.sort() 改变原数组 i=np.argsort(x) 返回排序好的索引值 x[i] 使用花哨索引返回排序好的数组 x=np.random.randint(0,10,(4,6)) np.sort(x 阅读全文
posted @ 2019-04-01 17:07 saber丶吾王 阅读(103) 评论(0) 推荐(0)
摘要:逻辑符 : == != < > <= >= x=np.array([1,3,5]) x<3 array([True,False,,False]) (2*x) == (x*2) array([False,False,,False]) 统计个数: np.count_nonzero(x>6) np.sum 阅读全文
posted @ 2019-04-01 16:35 saber丶吾王 阅读(140) 评论(0) 推荐(0)
摘要:广播: x= np.arange(12).reshape((3,4)) a= np.arange(3) b=np.arange(3)[;,np.newaxis] c=a+b a,b会扩散成公共的形状进行计算 广播规则: 如果两个数组的维度数不相同,那么小维度的数组形状将会在最左边补上1 如果两个数组 阅读全文
posted @ 2019-04-01 15:10 saber丶吾王 阅读(150) 评论(0) 推荐(0)
摘要:通用函数: np.add 加 np.subtract 减 np.multiply 乘 np.divide 除 np.floor_divide 地板乘除法,取商 np.power 指数运算 np.power(3,x) 3^x np.exp e^x np.exp2 2^x np.mod 取余 np.ab 阅读全文
posted @ 2019-04-01 15:03 saber丶吾王 阅读(326) 评论(0) 推荐(0)
摘要:np.zeros(10,dtype=int) #创建全为0的一位数组 np.ones((3,5),dtype=float) #创建3*5的二维全为1的数组 np.full((3,5),3.14) #创建全为3.14的3*5数组 np.arange(0,20,2) #创建0-20步长为2的线性序列数组 阅读全文
posted @ 2019-04-01 11:07 saber丶吾王 阅读(262) 评论(0) 推荐(0)