Python学习

from __future__ import print_function  
import pandas as pd  
  
catering_sale =(r'C:\Users\Administrator\Desktop\catering_sale.xls') #餐饮数据  
data = pd.read_excel(catering_sale, index_col = u'日期') #读取数据,指定“日期”列为索引列  
print(data)
data = data[(data[u'销量'] > 400)&(data[u'销量'] < 5000)] #过滤异常数据  
statistics = data.describe() #保存基本统计量  
print(type(statistics))
statistics.loc['range'] = statistics.loc['max']-statistics.loc['min'] #极差  
statistics.loc['var'] = statistics.loc['std']/statistics.loc['mean'] #变异系数  std = 标准差 mean = 平均值
statistics.loc['dis'] = statistics.loc['75%']-statistics.loc['25%'] #四分位数间距  
  
print(statistics) 

import numpy as np  
import matplotlib.pyplot as pt  
x = np.arange(0 , 360,step = 10)  
print(x)
y = np.sin( x*np.pi/180.0 )  
print(y)
pt.plot(x,y,'ro',color = 'b')  
pt.xlim(0,360)  
pt.ylim(-1.2,1.2)  
pt.title("picture one")  
pt.show()  

 
size = 1
x = np.arange(size)
a = np.random.random(size)
b = np.random.random(size)
c = np.random.random(size)

total_width, n = 0.8, 3
width = total_width / n
x = x - (total_width - width) / 2
for i in np.arange(10):
    if i <=  5:
        pt.bar(x + i*width, i, width=width, label='a',fc = 'b',ec='black')
    else:
        pt.bar(x + i*width, -i%5, width=width, label='a',fc = 'b',ec='black')

pt.title("picture two")
#pt.bar(x + width, b, width=width, label='b')
#pt.bar(x + 2 * width, c, width=width, label='c')
#pt.legend()
pt.show()

labels = 'Froges', 'Hogs', 'Dogs', 'Logs'
colors = ['yellow','lightskyblue','lightred','orangegreen']
fracs = [15, 30, 45, 10]
explode = [0, 0.1, 0, 0] # 0.1 凸出这部分,
pt.axes(aspect=1)  # set this , Figure is round, otherwise it is an ellipse
#autopct ,show percet
pt.pie(x=fracs, labels=labels, explode=explode,autopct='%3.1f %%',
        shadow=True, labeldistance=1.1, startangle = 90,pctdistance = 0.6
 
        )
pt.show()

 

posted @ 2017-09-21 21:00  白痴的救赎  阅读(384)  评论(0编辑  收藏  举报