数据分析:
最基础的库是Numpy(c语言实现,python接口,速度快),是其他众多数据分析库的基础,表达N维数组的最基础库
Pandas:数据分析高层次应用,提供了简单易用的数据结构分析工具,理解数据类型与数据索引的关系,操作索引及操作数据
Scipy:提供了一批数学算法及工程数据运算功能,类似matlab,用于数学科学计算
数据可视化:
文本处理:
机器学习:
#HollandRadarDraw
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
matplotlib.rcParams['font.family']='SimHei'
radar_labels = np.array(['研究型(I)','艺术型(A)','社会型(S)',\
'企业型(E)','常规型(C)','现实型(R)']) #雷达标签
nAttr = 6
data = np.array([[0.40, 0.32, 0.35, 0.30, 0.30, 0.88],
[0.85, 0.35, 0.30, 0.40, 0.40, 0.30],
[0.43, 0.89, 0.30, 0.28, 0.22, 0.30],
[0.30, 0.25, 0.48, 0.85, 0.45, 0.40],
[0.20, 0.38, 0.87, 0.45, 0.32, 0.28],
[0.34, 0.31, 0.38, 0.40, 0.92, 0.28]]) #数据值
data_labels = ('艺术家', '实验员', '工程师', '推销员', '社会工作者','记事员')
angles = np.linspace(0, 2*np.pi, nAttr, endpoint=False)
data = np.concatenate((data, [data[0]]))
angles = np.concatenate((angles, [angles[0]]))
fig = plt.figure(facecolor="white")
plt.subplot(111, polar=True)
plt.plot(angles,data,'o-', linewidth=1, alpha=0.2)
plt.fill(angles,data, alpha=0.25)
plt.thetagrids(angles*180/np.pi, radar_labels)
plt.figtext(0.52, 0.95, '霍兰德人格分析', ha='center', size=20)
legend = plt.legend(data_labels, loc=(0.94, 0.80), labelspacing=0.1)
plt.setp(legend.get_texts(), fontsize='large')
plt.grid(True)
plt.savefig('holland_radar.jpg')
plt.show()
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Y3VWUdFb-1588092553211)(week9_files/week9_2_0.svg)]
艺术:思想优先,编程是手段
设计:想法和编程同等重要
工程:编程优先,思想次之
#RoseDraw.py
import turtle as t
# 定义一个曲线绘制函数
def DegreeCurve(n, r, d=1):
for i in range(n):
t.left(d)
t.circle(r, abs(d))
# 初始位置设定
s = 0.2 # size
t.setup(450*5*s, 750*5*s)
t.pencolor("black")
t.fillcolor("red")
t.speed(100)
t.penup()
t.goto(0, 900*s)
t.pendown()
# 绘制花朵形状
t.begin_fill()
t.circle(200*s,30)
DegreeCurve(60, 50*s)
t.circle(200*s,30)
DegreeCurve(4, 100*s)
t.circle(200*s,50)
DegreeCurve(50, 50*s)
t.circle(350*s,65)
DegreeCurve(40, 70*s)
t.circle(150*s,50)
DegreeCurve(20, 50*s, -1)
t.circle(400*s,60)
DegreeCurve(18, 50*s)
t.fd(250*s)
t.right(150)
t.circle(-500*s,12)
t.left(140)
t.circle(550*s,110)
t.left(27)
t.circle(650*s,100)
t.left(130)
t.circle(-300*s,20)
t.right(123)
t.circle(220*s,57)
t.end_fill()
# 绘制花枝形状
t.left(120)
t.fd(280*s)
t.left(115)
t.circle(300*s,33)
t.left(180)
t.circle(-300*s,33)
DegreeCurve(70, 225*s, -1)
t.circle(350*s,104)
t.left(90)
t.circle(200*s,105)
t.circle(-500*s,63)
t.penup()
t.goto(170*s,-30*s)
t.pendown()
t.left(160)
DegreeCurve(20, 2500*s)
DegreeCurve(220, 250*s, -1)
# 绘制一个绿色叶子
t.fillcolor('green')
t.penup()
t.goto(670*s,-180*s)
t.pendown()
t.right(140)
t.begin_fill()
t.circle(300*s,120)
t.left(60)
t.circle(300*s,120)
t.end_fill()
t.penup()
t.goto(180*s,-550*s)
t.pendown()
t.right(85)
t.circle(600*s,40)
# 绘制另一个绿色叶子
t.penup()
t.goto(-150*s,-1000*s)
t.pendown()
t.begin_fill()
t.rt(120)
t.circle(300*s,115)
t.left(75)
t.circle(300*s,100)
t.end_fill()
t.penup()
t.goto(430*s,-1070*s)
t.pendown()
t.right(30)
t.circle(-600*s,35)
t.done()
描述
获取系统的递归深度、当前执行文件路径、系统最大UNICODE编码值等3个信息,并打印输出。
输出格式如下:
RECLIMIT:<深度>, EXEPATH:<文件路径>, UNICODE:<最大编码值>
import sys
print("RECLIMIT:{}, EXEPATH:{}, UNICODE:{}".format(sys.getrecursionlimit(), sys.executable,sys.maxunicode))
RECLIMIT:3000, EXEPATH:E:\creative\python\python.exe, UNICODE:1114111
描述
tabulate能够对二维数据进行表格输出,是Python优秀的第三方计算生态。
参考编程模板中给定的数据和代码,编写程序,能够输出如下风格效果的表格数据。
from tabulate import tabulate
data = [ ["北京理工大学", "985", 2000], \
["清华大学", "985", 3000], \
["大连理工大学", "985", 4000], \
["深圳大学", "211", 2000], \
["沈阳大学", "省本", 2000], \
]
print(tabulate(data, tablefmt="grid"))
+--------------+------+------+
| 北京理工大学 | 985 | 2000 |
+--------------+------+------+
| 清华大学 | 985 | 3000 |
+--------------+------+------+
| 大连理工大学 | 985 | 4000 |
+--------------+------+------+
| 深圳大学 | 211 | 2000 |
+--------------+------+------+
| 沈阳大学 | 省本 | 2000 |
+--------------+------+------+
期末考试
s=input()
ls=s.split(' ')
for i in ls:
print(i,end='')
Alice+Bob
with open('latex.log', 'r', encoding='utf-8') as f:
row_set = set(f.readlines())
print('共{}关键行'.format(len(row_set)))
共411关键行
即,读入字典key:value模式,输出value:key模式。
try:
s=input()
dict_1 = dict(eval(s))
dict_2 = dict(zip(dict_1.values(),dict_1.keys()))
print(dict_2)
except:
print('输入错误')
{1: 'a', 2: 'b'}
如果存在多个单词出现频率一致,请输出按照Unicode排序后最大的单词。
#标准答案
import jieba
f = open("沉默的羔羊.txt",encoding='utf-8')
ls = jieba.lcut(f.read())
#ls = f.read().split()
d = {}
for w in ls:
d[w] = d.get(w, 0) + 1
maxc = 0
maxw = ""
for k in d:
if d[k] > maxc and len(k) > 2:
maxc = d[k]
maxw = k
if d[k] == maxc and len(k) > 2 and k > maxw:
maxw = k
print(maxw,maxc)
f.close()
史达琳 701