#python库中的基本用法 import pandas as pd # 调用pandas库 来读取excell的文件 import scipy.stats as ss #生成正太分布的库 import numpy as np import seaborn as sns df=pd.read_csv("./data/qb_data.csv") # 读取excell的文件 # print(df) # print(df.head(10)) # 得到数据的前十行 # print(type(df)) #求读取的数据的类型 # print(type(df["Name"])) # 求每列行的值的类型 # print(df.mean()) # 求均值 # print(df["Age"].mean()) #求指定的每一列的均值 # print(df["Cmp"].median) # 求指定的这一列的中位数 # print("求Att的分位数是:",df["Att"].quantile(q=0.5)) # 求分位数 # print(df.quantile(q=0.5)) # 求分位数 # print(df.mode()) # print("Age的众数:",df["Age"].mode()) #求众数 # print("Age的标准差:",df["Age"].std()) # 求标准差 # print("Age的方差:",df["Age"].var()) #求方差 # print("Age的和:",df["Age"].sum()) #求和 # print("Age的偏态系数:",df["Age"].skew()) #求偏态系数 # print("Age的和:",df["Age"].kurt()) #求峰态系数 # print(ss.norm) # print("Age的正态分布:",ss.norm.stats(moments="mvsk")) #求正态分布 # print(ss.norm.pdf(0.0)) #分布函数在0上面的值 # print(ss.norm.ppf(0.9)) #累计值 # print(ss.norm.cdf(2)) #从负无穷到2的累计概率是多少 # print(ss.norm.cdf(2)-ss.norm.cdf(-2)) # print(ss.norm.rvs(size=10)) # 10个符合正态分布的数字 # print(df["Age"].sample(10)) # 对其中的一列进行十个抽样 sns.set_style(style="ticks") sns.set_context(context="poster",font_scale=0.5) sns.countplot(x="Age",data=df) # 直接调用seaborn库绘制柱状图 sl_s=df["TD"] print(sl_s.isnull()) #判断是否有异常值 print(sl_s[sl_s.isnull()]) print(df[df["TD"].isnull()]) sl_s=sl_s.dropna() print(sl_s.min()) print(sl_s.median()) print(sl_s.quantile(q=0.25)) print(sl_s.quantile(q=0.75)) import seaborn as sns import matplotlib.pyplot as plt plt.title("Age") plt.xlabel("age") plt.ylabel("Number") plt.bar(np.arange(len(df["Age"].value_counts()))+0.5,df["Age"].value_counts()) plt.xticks(np.arange(len(df["Age"].value_counts()))+0.5,df["Age"].value_counts().index) for x,y in zip(np.arange(len(df["Age"].value_counts()))+0.5,df["Age"].value_counts()): plt.text(x,y,y,ha="center",va="bottom") plt.savefig('Age.png') #保存图片 plt.show() print("这是Cmp") plt.title("Cmp") plt.xlabel("cmp") plt.ylabel("Number") plt.xticks(np.arange(len(df["Cmp"].value_counts()))+0.5,df["Cmp"].value_counts().index) plt.bar(np.arange(len(df["Cmp"].value_counts()))+0.5,df["Cmp"].value_counts(),width=0.5) plt.axis([0,20,0,40]) for x,y in zip(np.arange(len(df["Cmp"].value_counts()))+0.5,df["Cmp"].value_counts()): plt.text(x,y,y,ha="center",va="bottom") plt.savefig('Cmp.png') #保存图片 plt.show() print("这是TD") plt.title("TD") plt.xlabel("td") plt.ylabel("Number") # sns.set_style(style="whitegrid") # sns.set_context(context="postor",font_scale=0.05) plt.xticks(np.arange(len(df["TD"].value_counts()))+0.5,df["TD"].value_counts().index) # plt.axis([0,20,0,30]) plt.bar(np.arange(len(df["TD"].value_counts()))+0.5,df["TD"].value_counts(),width=0.5) for x,y in zip(np.arange(len(df["TD"].value_counts()))+0.5,df["TD"].value_counts()): plt.text(x,y,y,ha="center",va="bottom") plt.savefig('TD.png') #保存图片 plt.show() print("——————————————————"*20) print(np.histogram(sl_s.values,bins=np.arange(20,50,100))) qb_data.csv的数据如下: Name,Age,Year,Cmp,Att,Yds,TD Peyton Manning,38,1998,326,575,3739,26 Peyton Manning,38,1999,331,533,4135,26 Peyton Manning,38,2000,357,571,4413,33 Peyton Manning,38,2001,343,547,4131,26 Peyton Manning,38,2002,392,591,4200,27 Peyton Manning,38,2003,379,566,4267,29 Peyton Manning,38,2004,336,497,4557,49 Peyton Manning,38,2005,305,453,3747,28 Peyton Manning,38,2006,362,557,4397,31 Peyton Manning,38,2007,337,515,4040,31 Peyton Manning,38,2008,371,555,4002,27 Peyton Manning,38,2009,393,571,4500,33 Peyton Manning,38,2010,450,679,4700,33 Peyton Manning,38,2011,0,0,0,0 Peyton Manning,38,2012,400,583,4659,37 Peyton Manning,38,2013,450,659,5477,55 Peyton Manning,38,2014,395,597,4727,39 Peyton Manning,38,2014,5927,9049,69691,530 Brett Favre,41,1991,0,4,0,0 Brett Favre,41,1992,302,471,3227,18 Brett Favre,41,1993,318,522,3303,19 Brett Favre,41,1994,363,582,3882,33 Brett Favre,41,1995,359,570,4413,38 Brett Favre,41,1996,325,543,3899,39 Brett Favre,41,1997,304,513,3867,35 Brett Favre,41,1998,347,551,4212,31 Brett Favre,41,1999,341,595,4091,22 Brett Favre,41,2000,338,580,3812,20 Brett Favre,41,2001,314,510,3921,32 Brett Favre,41,2002,341,551,3658,27 Brett Favre,41,2003,308,471,3361,32 Brett Favre,41,2004,346,540,4088,30 Brett Favre,41,2005,372,607,3881,20 Brett Favre,41,2006,343,613,3885,18 Brett Favre,41,2007,356,535,4155,28 Brett Favre,41,2008,343,522,3472,22 Brett Favre,41,2009,363,531,4202,33 Brett Favre,41,2010,217,358,2509,11 Brett Favre,41,2010,6300,10169,71838,508 Dan Marino,38,1983,173,296,2210,20 Dan Marino,38,1984,362,564,5084,48 Dan Marino,38,1985,336,567,4137,30 Dan Marino,38,1986,378,623,4746,44 Dan Marino,38,1987,263,444,3245,26 Dan Marino,38,1988,354,606,4434,28 Dan Marino,38,1989,308,550,3997,24 Dan Marino,38,1990,306,531,3563,21 Dan Marino,38,1991,318,549,3970,25 Dan Marino,38,1992,330,554,4116,24 Dan Marino,38,1993,91,150,1218,8 Dan Marino,38,1994,385,615,4453,30 Dan Marino,38,1995,309,482,3668,24 Dan Marino,38,1996,221,373,2795,17 Dan Marino,38,1997,319,548,3780,16 Dan Marino,38,1998,310,537,3497,23 Dan Marino,38,1999,204,369,2448,12 Dan Marino,38,2010,4967,8358,61361,420 Drew Brees,35,2001,15,27,221,1 Drew Brees,35,2002,320,526,3284,17 Drew Brees,35,2003,205,356,2108,11 Drew Brees,35,2004,262,400,3159,27 Drew Brees,35,2005,323,500,3576,24 Drew Brees,35,2006,356,554,4418,26 Drew Brees,35,2007,440,652,4423,28 Drew Brees,35,2008,413,635,5069,34 Drew Brees,35,2009,363,514,4388,34 Drew Brees,35,2010,448,658,4620,33 Drew Brees,35,2011,468,657,5476,46 Drew Brees,35,2012,422,670,5177,43 Drew Brees,35,2013,446,650,5162,39 Drew Brees,35,2014,456,659,4952,33 Drew Brees,35,2010,4937,7458,56033,396 Tom Brady,37,2000,1,3,6,0 Tom Brady,37,2001,264,413,2843,18 Tom Brady,37,2002,373,601,3764,28 Tom Brady,37,2003,317,527,3620,23 Tom Brady,37,2004,288,474,3692,28 Tom Brady,37,2005,334,530,4110,26 Tom Brady,37,2006,319,516,3529,24 Tom Brady,37,2007,398,578,4806,50 Tom Brady,37,2008,7,11,76,0 Tom Brady,37,2009,371,565,4398,28 Tom Brady,37,2010,324,492,3900,36 Tom Brady,37,2011,401,611,5235,39 Tom Brady,37,2012,401,637,4827,34 Tom Brady,37,2013,380,628,4343,25 Tom Brady,37,2014,373,582,4109,33 Tom Brady,37,2010,4551,7168,53258,392 Fran Tarkenton,38,1961,157,280,1997,18 Fran Tarkenton,38,1962,163,329,2595,22 Fran Tarkenton,38,1963,170,297,2311,15 Fran Tarkenton,38,1964,171,306,2506,22 Fran Tarkenton,38,1965,171,329,2609,19 Fran Tarkenton,38,1966,192,358,2561,17 Fran Tarkenton,38,1967,204,377,3088,29 Fran Tarkenton,38,1968,182,337,2555,21 Fran Tarkenton,38,1969,220,409,2918,23 Fran Tarkenton,38,1970,219,389,2777,19 Fran Tarkenton,38,1971,226,386,2567,11 Fran Tarkenton,38,1972,215,378,2651,18 Fran Tarkenton,38,1973,169,274,2113,15 Fran Tarkenton,38,1974,199,351,2598,17 Fran Tarkenton,38,1975,273,425,2994,25 Fran Tarkenton,38,1976,255,412,2961,17 Fran Tarkenton,38,1977,155,258,1734,9 Fran Tarkenton,38,1978,345,572,3468,25 Fran Tarkenton,38,2010,3686,6467,47003,342 John Elway,38,1983,123,259,1663,7 John Elway,38,1984,214,380,2598,18 John Elway,38,1985,327,605,3891,22 John Elway,38,1986,280,504,3485,19 John Elway,38,1987,224,410,3198,19 John Elway,38,1988,274,496,3309,17 John Elway,38,1989,223,416,3051,18 John Elway,38,1990,294,502,3526,15 John Elway,38,1991,242,451,3253,13 John Elway,38,1992,174,316,2242,10 John Elway,38,1993,348,551,4030,25 John Elway,38,1994,307,494,3490,16 John Elway,38,1995,316,542,3970,26 John Elway,38,1996,287,466,3328,26 John Elway,38,1997,280,502,3635,27 John Elway,38,1998,210,356,2806,22 John Elway,38,2010,4123,7250,51475,300 Warren Moon,44,1984,259,450,3338,12 Warren Moon,44,1985,200,377,2709,15 Warren Moon,44,1986,256,488,3489,13 Warren Moon,44,1987,184,368,2806,21 Warren Moon,44,1988,160,294,2327,17 Warren Moon,44,1989,280,464,3631,23 Warren Moon,44,1990,362,584,4689,33 Warren Moon,44,1991,404,655,4690,23 Warren Moon,44,1992,224,346,2521,18 Warren Moon,44,1993,303,520,3485,21 Warren Moon,44,1994,371,601,4264,18 Warren Moon,44,1995,377,606,4228,33 Warren Moon,44,1996,134,247,1610,7 Warren Moon,44,1997,313,528,3678,25 Warren Moon,44,1998,145,258,1632,11 Warren Moon,44,1999,1,3,20,0 Warren Moon,44,2000,15,34,208,1 Warren Moon,44,2010,3988,6823,49325,291 Johny Unitas,40,1956,110,198,1498,9 Johny Unitas,40,1957,172,301,2550,24 Johny Unitas,40,1958,136,263,2007,19 Johny Unitas,40,1959,193,367,2899,32 Johny Unitas,40,1960,190,378,3099,25 Johny Unitas,40,1961,229,420,2990,16 Johny Unitas,40,1962,222,389,2967,23 Johny Unitas,40,1963,237,410,3481,20 Johny Unitas,40,1964,158,305,2824,19 Johny Unitas,40,1965,164,282,2530,23 Johny Unitas,40,1966,195,348,2748,22 Johny Unitas,40,1967,255,436,3428,20 Johny Unitas,40,1968,11,32,139,2 Johny Unitas,40,1969,178,327,2342,12 Johny Unitas,40,1970,166,321,2213,14 Johny Unitas,40,1971,92,176,942,3 Johny Unitas,40,1972,88,157,1111,4 Johny Unitas,40,1973,34,76,471,3 Johny Unitas,40,2010,2830,5186,40239,290 Vinny Testaverde,44,1987,71,165,1081,5 Vinny Testaverde,44,1988,222,466,3240,13 Vinny Testaverde,44,1989,258,480,3133,20 Vinny Testaverde,44,1990,203,365,2818,17 Vinny Testaverde,44,1991,166,326,1994,8 Vinny Testaverde,44,1992,206,358,2554,14 Vinny Testaverde,44,1993,130,230,1797,14 Vinny Testaverde,44,1994,207,376,2575,16 Vinny Testaverde,44,1995,241,392,2883,17 Vinny Testaverde,44,1996,325,549,4177,33 Vinny Testaverde,44,1997,271,470,2971,18 Vinny Testaverde,44,1998,259,421,3256,29 Vinny Testaverde,44,1999,10,15,96,1 Vinny Testaverde,44,2000,328,590,3732,21 Vinny Testaverde,44,2001,260,441,2752,15 Vinny Testaverde,44,2002,54,83,499,3 Vinny Testaverde,44,2003,123,198,1385,7 Vinny Testaverde,44,2004,297,495,3532,17 Vinny Testaverde,44,2005,60,106,777,1 Vinny Testaverde,44,2006,2,3,29,1 Vinny Testaverde,44,2007,94,172,952,5 Vinny Testaverde,44,2010,3787,6701,46233,275 Joe Montana,38,1979,13,23,96,1 Joe Montana,38,1980,176,273,1795,15 Joe Montana,38,1981,311,488,3565,19 Joe Montana,38,1982,213,346,2613,17 Joe Montana,38,1983,332,515,3910,26 Joe Montana,38,1984,279,432,3630,28 Joe Montana,38,1985,303,494,3653,27 Joe Montana,38,1986,191,307,2236,8 Joe Montana,38,1987,266,398,3054,31 Joe Montana,38,1988,238,397,2981,18 Joe Montana,38,1989,271,386,3521,26 Joe Montana,38,1990,321,520,3944,26 Joe Montana,38,1992,15,21,126,2 Joe Montana,38,1993,181,298,2144,13 Joe Montana,38,1994,299,493,3283,16 Joe Montana,38,2010,3409,5391,40551,273 Dave Krieg,40,1980,0,2,0,0 Dave Krieg,40,1981,64,112,843,7 Dave Krieg,40,1982,49,78,501,2 Dave Krieg,40,1983,147,243,2139,18 Dave Krieg,40,1984,276,480,3671,32 Dave Krieg,40,1985,285,532,3602,27 Dave Krieg,40,1986,225,375,2921,21 Dave Krieg,40,1987,178,294,2131,23 Dave Krieg,40,1988,134,228,1741,18 Dave Krieg,40,1989,286,499,3309,21 Dave Krieg,40,1990,265,448,3194,15 Dave Krieg,40,1991,187,285,2080,11 Dave Krieg,40,1992,230,413,3115,15 Dave Krieg,40,1993,105,189,1238,7 Dave Krieg,40,1994,131,212,1629,14 Dave Krieg,40,1995,304,521,3554,16 Dave Krieg,40,1996,226,377,2278,14 Dave Krieg,40,1997,1,2,2,0 Dave Krieg,40,1998,12,21,199,0 Dave Krieg,40,2010,3105,5311,38147,261 Eli Manning,33,2004,95,197,1043,6 Eli Manning,33,2005,294,557,3762,24 Eli Manning,33,2006,301,522,3244,24 Eli Manning,33,2007,297,529,3336,23 Eli Manning,33,2008,289,479,3238,21 Eli Manning,33,2009,317,509,4021,27 Eli Manning,33,2010,339,539,4002,31 Eli Manning,33,2011,359,589,4933,29 Eli Manning,33,2012,321,536,3948,26 Eli Manning,33,2013,317,551,3818,18 Eli Manning,33,2014,379,601,4410,30 Eli Manning,33,2010,3308,5609,39755,259 Sonny Jurgensen,40,1957,33,70,470,5 Sonny Jurgensen,40,1958,12,22,259,0 Sonny Jurgensen,40,1959,3,5,27,1 Sonny Jurgensen,40,1960,24,44,486,5 Sonny Jurgensen,40,1961,235,416,3723,32 Sonny Jurgensen,40,1962,196,366,3261,22 Sonny Jurgensen,40,1963,99,184,1413,11 Sonny Jurgensen,40,1964,207,385,2934,24 Sonny Jurgensen,40,1965,190,356,2367,15 Sonny Jurgensen,40,1966,254,436,3209,28 Sonny Jurgensen,40,1967,288,508,3747,31 Sonny Jurgensen,40,1968,167,292,1980,17 Sonny Jurgensen,40,1969,274,442,3102,22 Sonny Jurgensen,40,1970,202,337,2354,23 Sonny Jurgensen,40,1971,16,28,170,0 Sonny Jurgensen,40,1972,39,59,633,2 Sonny Jurgensen,40,1973,87,145,904,6 Sonny Jurgensen,40,1974,107,167,1185,11 Sonny Jurgensen,40,2010,2433,4262,32224,255 Dan Fouts,36,1973,87,194,1126,6 Dan Fouts,36,1974,115,237,1732,8 Dan Fouts,36,1975,106,195,1396,2 Dan Fouts,36,1976,208,359,2535,14 Dan Fouts,36,1977,69,109,869,4 Dan Fouts,36,1978,224,381,2999,24 Dan Fouts,36,1979,332,530,4082,24 Dan Fouts,36,1980,348,589,4715,30 Dan Fouts,36,1981,360,609,4802,33 Dan Fouts,36,1982,204,330,2883,17 Dan Fouts,36,1983,215,340,2975,20 Dan Fouts,36,1984,317,507,3740,19 Dan Fouts,36,1985,254,430,3638,27 Dan Fouts,36,1986,252,430,3031,16 Dan Fouts,36,1987,206,364,2517,10 Dan Fouts,36,2010,3297,5604,43040,254 Philip Rivers,33,2004,5,8,33,1 Philip Rivers,33,2005,12,22,115,0 Philip Rivers,33,2006,284,460,3388,22 Philip Rivers,33,2007,277,460,3152,21 Philip Rivers,33,2008,312,478,4009,34 Philip Rivers,33,2009,317,486,4254,28 Philip Rivers,33,2010,357,541,4710,30 Philip Rivers,33,2011,366,582,4624,27 Philip Rivers,33,2012,338,527,3606,26 Philip Rivers,33,2013,378,544,4478,32 Philip Rivers,33,2014,379,570,4286,31 Philip Rivers,33,2010,3025,4678,36655,252 Ben Roethlisberger,32,2004,196,295,2621,17 Ben Roethlisberger,32,2005,168,268,2385,17 Ben Roethlisberger,32,2006,280,469,3513,18 Ben Roethlisberger,32,2007,264,404,3154,32 Ben Roethlisberger,32,2008,281,469,3301,17 Ben Roethlisberger,32,2009,337,506,4328,26 Ben Roethlisberger,32,2010,240,389,3200,17 Ben Roethlisberger,32,2011,324,513,4077,21 Ben Roethlisberger,32,2012,284,449,3265,26 Ben Roethlisberger,32,2013,375,584,4261,28 Ben Roethlisberger,32,2014,408,608,4952,32 Ben Roethlisberger,32,2010,3157,4954,39057,251 Drew Bledsoe,34,1993,214,429,2494,15 Drew Bledsoe,34,1994,400,691,4555,25 Drew Bledsoe,34,1995,323,636,3507,13 Drew Bledsoe,34,1996,373,623,4086,27 Drew Bledsoe,34,1997,314,522,3706,28 Drew Bledsoe,34,1998,263,481,3633,20 Drew Bledsoe,34,1999,305,539,3985,19 Drew Bledsoe,34,2000,312,531,3291,17 Drew Bledsoe,34,2001,40,66,400,2 Drew Bledsoe,34,2002,375,610,4359,24 Drew Bledsoe,34,2003,274,471,2860,11 Drew Bledsoe,34,2004,256,450,2932,20 Drew Bledsoe,34,2005,300,499,3639,23 Drew Bledsoe,34,2006,90,169,1164,7 Drew Bledsoe,34,2010,3839,6717,44611,251 Boomer Esiason,36,1984,51,102,530,3 Boomer Esiason,36,1985,251,431,3443,27 Boomer Esiason,36,1986,273,469,3959,24 Boomer Esiason,36,1987,240,440,3321,16 Boomer Esiason,36,1988,223,388,3572,28 Boomer Esiason,36,1989,258,455,3525,28 Boomer Esiason,36,1990,224,402,3031,24 Boomer Esiason,36,1991,233,413,2883,13 Boomer Esiason,36,1992,144,278,1407,11 Boomer Esiason,36,1993,288,473,3421,16 Boomer Esiason,36,1994,255,440,2782,17 Boomer Esiason,36,1995,221,389,2275,16 Boomer Esiason,36,1996,190,339,2293,11 Boomer Esiason,36,1997,118,186,1478,13 Boomer Esiason,36,2010,2969,5205,37920,247 John Hadle,37,1962,107,260,1632,15 John Hadle,37,1963,28,64,502,6 John Hadle,37,1964,147,274,2157,18 John Hadle,37,1965,174,348,2798,20 John Hadle,37,1966,200,375,2846,23 John Hadle,37,1967,217,427,3365,24 John Hadle,37,1968,208,440,3473,27 John Hadle,37,1969,158,324,2253,10 John Hadle,37,1970,162,327,2388,22 John Hadle,37,1971,233,431,3075,21 John Hadle,37,1972,190,370,2449,15 John Hadle,37,1973,135,258,2008,22 John Hadle,37,1974,142,299,1752,8 John Hadle,37,1975,191,353,2095,6 John Hadle,37,1976,60,113,634,7 John Hadle,37,1977,11,24,76,0 John Hadle,37,2010,2363,4687,33503,244 Y A Tittle,38,1948,161,289,2522,16 Y A Tittle,38,1949,148,289,2209,14 Y A Tittle,38,1950,161,315,1884,8 Y A Tittle,38,1951,63,114,808,8 Y A Tittle,38,1952,106,208,1407,11 Y A Tittle,38,1953,149,259,2121,20 Y A Tittle,38,1954,170,295,2205,9 Y A Tittle,38,1955,147,287,2185,17 Y A Tittle,38,1956,124,218,1641,7 Y A Tittle,38,1957,176,279,2157,13 Y A Tittle,38,1958,120,208,1467,9 Y A Tittle,38,1959,102,199,1331,10 Y A Tittle,38,1960,69,127,694,4 Y A Tittle,38,1961,163,285,2272,17 Y A Tittle,38,1962,200,375,3224,33 Y A Tittle,38,1963,221,367,3145,36 Y A Tittle,38,1964,147,281,1798,10 Y A Tittle,38,2010,2427,4395,33070,242 Tony Romo,34,2004,0,0,0,0 Tony Romo,34,2005,0,0,0,0 Tony Romo,34,2006,220,337,2903,19 Tony Romo,34,2007,335,520,4211,36 Tony Romo,34,2008,276,450,3448,26 Tony Romo,34,2009,347,550,4483,26 Tony Romo,34,2010,148,213,1605,11 Tony Romo,34,2011,346,522,4184,31 Tony Romo,34,2012,425,648,4903,28 Tony Romo,34,2013,342,535,3828,31 Tony Romo,34,2014,304,435,3705,34 Tony Romo,34,2010,2743,4210,33270,242 # 折线图: import pandas as pd # 调用pandas库 来读取excell的文件 import scipy.stats as ss #生成正太分布的库 import numpy as np import seaborn as sns import matplotlib.pyplot as plt df=pd.read_csv("./data/qb_data.csv") # 读取excell的文件 sns.set_style(style="whitegrid") #背景的样式 sns.set_context(context="poster",font_scale=0.8) sub_df=df.groupby("Age").mean() # sns.pointplot(sub_df.index,sub_df["Year"]) sns.pointplot(x="Age",y="Cmp",data=df) plt.show() #直方图: import seaborn as sns import matplotlib.pyplot as plt df=pd.read_csv("./data/qb_data.csv") # 读取excell的文件 sns.set_style(style="whitegrid") #背景的样式 sns.set_context(context="poster",font_scale=0.8) # context="poster" 文字的格式,font_scale=0.8 字体的大小 f=plt.figure() f.add_subplot(1,3,1) #设置在一个页面上的 1行3列第几个 sns.distplot(df["TD"],bins=30) #kde=False 如果kde 等于false 那么折线图就没有了,如果 hist等于False 那么直方图就没有了 f.add_subplot(1,3,2) sns.distplot(df["Age"],bins=30) f.add_subplot(1,3,3) sns.distplot(df["Cmp"],bins=30) plt.show() #箱型图: import pandas as pd # 调用pandas库 来读取excell的文件 import scipy.stats as ss #生成正太分布的库 import numpy as np import seaborn as sns import matplotlib.pyplot as plt df=pd.read_csv("./data/qb_data.csv") # 读取excell的文件 sns.set_style(style="whitegrid") #背景的样式 sns.set_context(context="poster",font_scale=0.8) # context="poster" 文字的格式,font_scale=0.8 字体的大小 sns.boxplot(x=df["Age"],saturation=0.75,whis=3) # saturation方框的边界 whis上分位数的几倍是他的间距 plt.show() # 饼图: import pandas as pd # 调用pandas库 来读取excell的文件 import scipy.stats as ss #生成正太分布的库 import numpy as np import seaborn as sns import matplotlib.pyplot as plt df=pd.read_csv("./data/qb_data.csv") # 读取excell的文件 # sns.set_style(style="whitegrid") #背景的样式 # sns.set_context(context="poster",font_scale=0.8) lbs=df["Age"].value_counts().index # 这是修饰加上各个形状的分类 explodes=[0.1 if i ==38 else 0 for i in lbs] # 如果想要着重强调某个部位就是把它分离开... # 这里面我强调的是38的部分 plt.pie(df["Age"].value_counts(normalize=True),explode=explodes,labels=lbs,autopct="%1.1f%%") # autopct="%1.1f%% 添加百分比,colors=sns.color_palette("Reds") 指定颜色样式 plt.show()
python读excel实现数据可视化
阅读:5025 输入:2019-11-09 20:30:17
- 上一篇:生成多个不重复的随机数字php
- 下一篇:画布引起的matplotlib绘图中文乱码