@SuHongjun
2020-05-28T09:56:56.000000Z
字数 2074
阅读 305
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 xlrd3
xl = 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 matplotlib
import matplotlib.pyplot as plt
import numpy as np
import 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 locations
width = 0.35 # the width of the bars
fig, 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 offset
textcoords="offset points",
ha='center', va='bottom')
autolabel(rects1)
autolabel(rects2)
fig.tight_layout()
plt.show()