
数据分析与可视化
进击的rookie of python
print('Welcome')
展开
-
Pandas_应用:通用分拆-应用-联合
1.应用'''选出小费比,最高的5组'''#显示所有列pd.set_option('display.max_columns', None)#显示所有行pd.set_option('display.max_rows', None)def top(df,n,column): return df.sort_values(by=column)[-n:]tips = pd....原创 2019-03-18 09:37:11 · 247 阅读 · 0 评论 -
Pandas_数据透视表与交叉表
数据透视表 pivot_table()pivot_table(self, values=None, index=None, columns=None,aggfunc='mean', fill_value=None, margins=False,dropna=True, margins_name='All'):'''values:需要聚合的列名,默认所有数值的列index:在结果...原创 2019-03-18 11:42:46 · 878 阅读 · 0 评论 -
matplotlib_相关设置
pyplot.xlim([xmin],[xmax]) >>>设置或返回x轴显示范围pyplot.ylim([ymin],[ymax]) >>>设置或返回y轴显示范围pyplot.xlabel(xlabel,font...翻译 2019-04-04 13:11:05 · 348 阅读 · 0 评论 -
matplotlib_堆积&并列
堆积条形图from matplotlib import pyplot as pltplt.rcParams['font.sans-serif']=['SimHei'] # 用来正常显示中文标签plt.rcParams['axes.unicode_minus']=False # 用来正常显示负号x=[1,2,3,4,5]y=[6,10,4,5,1]y1=[2,6,3,8,5]...翻译 2019-04-06 22:08:44 · 424 阅读 · 0 评论 -
matplotlib_带误差棒的条形图
import matplotlib.pyplot as pltplt.rcParams['font.sans-serif']=['SimHei']x=np.arange(5)y=[100,68,79,91,82]err=[7,2,6,10,5]err_attr={"elinewidth":2,"ecolor":"black","capsize":3}plt.bar(x,y,...翻译 2019-04-07 09:41:43 · 4179 阅读 · 0 评论 -
matplotlib_图形样式
刻度定位器与刻度格式器import numpy as npimport matplotlib.pyplot as pltfrom matplotlib.ticker import AutoMinorLocator,MultipleLocator,FormatStrFormatterplt.rcParams['font.sans-serif']=['SimHei']plt.rcPa...原创 2019-04-07 18:45:03 · 382 阅读 · 0 评论 -
matplotlib_常见图
折线图matplotlib.pyplot.plot(* args,scalex = True,scaley = True,data = None,** kwargs)x:x轴上的数值y:y轴上的数值ls:线条风格lw:线条宽度color:颜色lable:标签文本返回值:Line2D对象散点图matplotlib.pyplot.scatter(x,...翻译 2019-04-02 13:16:51 · 589 阅读 · 0 评论 -
matplotlib_共享坐标轴
pyplot.subplots(nrows = 1,ncols = 1,sharex = False,sharey = False,squeeze = True,subplot_kw =无,gridspec_kw =无,** fig_kw )参数:nrows:行数ncols:列数sharex:是否共享X轴坐标sharey:是否共享Y轴坐标返回值:Figure,Axes对象数组...翻译 2019-04-08 12:40:35 · 6665 阅读 · 0 评论 -
Pandas_索引
行列取名data=np.random.randn(3,4)df1=pd.DataFrame(data,index=pd.Index(['a','b','c'],name='index',),columns=pd.Index(list('qwer'),name='columns'))print(df1)'''columns q w e ...原创 2019-02-15 10:59:57 · 177 阅读 · 0 评论 -
Pandas_算数与统计
算数与数据对齐1.相同维度'''在不重叠的地方引入了NA值重叠:series为index,dataframe为index,columns'''s1=pd.Series([1.2,3.4,-7.8,5.6],index=['d','a','c','b'])s2=pd.Series([1.1,2.2,3.3,4.4,5.5,6.6],index=['a','b','c','d','e...原创 2019-02-15 10:50:44 · 190 阅读 · 0 评论 -
Pandas_IO
1.CSV'''pd.read_scv()'''常见参数:filepath_or_buffer : 字符串,文件路径,或者文件句柄,或者字符串IOsep : 字符串,分割符,默认值为','delimiter : 定界符,备选分隔符(如果指定该参数,则sep参数失效)delim_whitespace :指定空格是否作为分隔符使用,等效于设定sep='\s+'。如果这个参数设定为T...原创 2019-01-17 19:42:12 · 161 阅读 · 0 评论 -
Pandas_数据转换
删除重复值frame=pd.DataFrame({'k1':['one','two']*3+['two'], 'k2':[1,1,2,3,3,4,4]})frame.duplicated() #判断重复行'''参数:subset:指定一列或多列进行比较,默认None所有列keep:‘first’默认,‘last’,保留第一个匹配到的或最后...原创 2019-01-18 14:58:14 · 243 阅读 · 0 评论 -
Pandas_切片,函数映射,排序观察
切片'''loc:标签,索引iloc:索引'''df.loc[1,1:3]#第一行,前2列df.loc[:,1:3]#所有行,前2列df.loc[:-1,-3:]#第一到倒数第二行,后3列函数映射df1=pd.DataFrame(np.random.randn(3,4),columns=list('dcbe'))''' d c ...原创 2019-01-16 13:44:47 · 213 阅读 · 0 评论 -
Pandas_联合与合并数据集
merge函数'''merge函数:参数 说明left 参与合并的左侧DataFrameright 参与合并的右侧DataFramehow “inner”,“outer(并集)”,“left”,“right"其中之一,默认为"inner”on 用于连接的列名,必须存在于左右两个DataFrame,如果不指定会自动...原创 2019-01-21 22:14:00 · 559 阅读 · 0 评论 -
Patents_groupby机制
1.使用列名分组df = pd.DataFrame({'key1':['a', 'a', 'b', 'b', 'a'], 'key2':['one', 'two', 'one', 'two', 'one'], 'data1':np.random.randn(5), 'data2':np.random.randn(5)})group_1=df.groupby...原创 2019-01-22 22:02:59 · 180 阅读 · 0 评论 -
pandas_重塑和透视
多层索引透视'''stack():将指定的列索引透视为第二层行索引,类型为Series参数level:层级序号或层级名称,默认-1level:层次索引的层级。从0开始分别对应第一层等索引,若为-1,则代表最里面一层索引。dropna:过滤掉缺失值,默认True'''f1=pd.DataFrame(np.arange(6).reshape(2,3), ...原创 2019-02-15 09:48:54 · 269 阅读 · 0 评论 -
Pandas_处理缺失值
frame.isnull() #bloomframe.notnull() #bloomframe.dropna() #返回没有NA的数据,默认axis=0,且出现一次NaN,该行就被删掉参数:axis,how='all':所有值为NaN才删掉frame.fillna() 缺失值补全参数:value 要替换的值,一般选中位值axisinplace 在原...原创 2019-02-15 09:52:27 · 246 阅读 · 0 评论 -
Pandas_分层索引
DataFrame分层索引frame=pd.DataFrame(np.arange(12).reshape(4,3), index=[['a','b','a','b'],[1,2,1,2]], columns=[['ohio','ohio','colo'],['red','red','yellow']])#分层索引...原创 2019-02-15 10:43:22 · 332 阅读 · 0 评论