@SuHongjun
2020-05-28T09:56:56.000000Z
字数 2074
阅读 360
Python 2020春季学期
下载页面:https://www.jetbrains.com/edu-products/download/#section=pycharm-edu
PyCharm基本操作:
Create New Project:设置 location、将Project Interpreter设为"Existing interpreter"
File -- Settings -- Editor:修改Color Scheme、Font
Ctrl + /:注释、取消注释
如何读取Excel文件中的数据:
以xlrd3模块为例:https://pypi.org/project/xlrd3/
安装xlrd3模块:
C:\Users\shj>pip install xlrd3 -i https://pypi.douban.com/simple
#对excel的操作import xlrd3xl = xlrd3.open_workbook(r'E:\try\Python\综合作业\zsyh.xls')#通过索引获取工作表table = xl.sheets()[0]print(table)# 获取第3行:营业收入的内容row = table.row_values(2) #索引从0开始print(row)# 获取第26行: 五、净利润的内容row = table.row_values(25)print(row)
统计图:matplotlib模块、.......
C:\Users\shj>pip install matplotlib -i https://pypi.douban.com/simple
import matplotlibimport matplotlib.pyplot as pltimport numpy as npimport xlrd3 #对excel的操作xl = xlrd3.open_workbook(r'E:\try\Python\综合作业\zsyh.xls')#通过索引获取工作表table = xl.sheets()[0]print(table)# 获取第1行:报表日期riqi = table.row_values(0) #索引从0开始print(riqi)riqi = riqi[1:]print(riqi)riqi = map(int,riqi)riqi = map(str,riqi)print(riqi)riqi = list(riqi)print(riqi)# 获取第3行:营业收入的内容yysr = table.row_values(2) #索引从0开始print(yysr)yysr = yysr[1:]print(yysr)# 获取第26行: 五、净利润的内容jlr = table.row_values(25)print(jlr)jlr = jlr[1:]print(jlr)#.......继续修改........以下代码......labels = ['G1', 'G2', 'G3', 'G4', 'G5']men_means = [20, 34, 30, 35, 27]women_means = [25, 32, 34, 20, 25]x = np.arange(len(labels)) # the label locationswidth = 0.35 # the width of the barsfig, ax = plt.subplots()rects1 = ax.bar(x - width/2, men_means, width, label='Men')rects2 = ax.bar(x + width/2, women_means, width, label='Women')# Add some text for labels, title and custom x-axis tick labels, etc.ax.set_ylabel('Scores')ax.set_title('Scores by group and gender')ax.set_xticks(x)ax.set_xticklabels(labels)ax.legend()def autolabel(rects):"""Attach a text label above each bar in *rects*, displaying its height."""for rect in rects:height = rect.get_height()ax.annotate('{}'.format(height),xy=(rect.get_x() + rect.get_width() / 2, height),xytext=(0, 3), # 3 points vertical offsettextcoords="offset points",ha='center', va='bottom')autolabel(rects1)autolabel(rects2)fig.tight_layout()plt.show()