math 库 random 库 wordcloud 库 巩固

jieba 库网址:
https://www.jianshu.com/p/883c2171cdb5

math 库

random 库

 

wordcloud 库

 


文本部分
import math

# 返回数字的绝对值
math.fabs(-10)

# 返回数字的上入整数
math.ceil(4.1)

math.ceil(-3.2)

# 返回 e 的 x 次幂
math.exp(1)

# 返回数字的下舍整数
math.floor(4.9)

math.floor(-5.6)

# 以 e 为基数
math.log(math.e)

# 以 2 为基数
math.log(8,2)

# 以 10 为基数
math.log10(100)

# 返回 x 的 (小数部分,整数部分)
math.modf(5.75)

math.modf(-5.75)

# x ** y , x 的 y 次幂
math.pow(2,3)

math.pow(2,-3)

# 返回数字 x 的平方根
math.sqrt(16)

math.sqrt(0)

# 返回 x 的反余弦弧度值
math.acos(1)

# 返回 x 的反正切弧度值
math.atan(1)

# math.atan2(y,x) 
# 返回给定的 X 及 Y 坐标值的反正切值
math.atan2(4,3)

# 返回 x 的弧度的余弦值
math.cos(0)

# 返回欧几里德范数 sqrt(x*x + y*y)
math.hypot(3, 4)

# 返回的 x 弧度的正弦值
math.sin(math.pi/2)

# 返回 x 弧度的正切值
math.tan(math.pi/2)

# 将弧度转换为角度
math.degrees(math.pi/2)

# 将角度转换为弧度
math.radians(90)

math.pi

math.e

 


import wordcloud
import jieba
import pandas as pd
import numpy as np
from PIL import Image
import matplotlib.pyplot as plt

WordCloud_params = '''
参数                   说明
background_color     背景颜色
max_words            最大词数
mask                 以某种形状进行绘制词云
stopwords            添加屏蔽词
font_path            更改字体
random_state         为每一个词返回一个 PIL 颜色
width                图片的宽
height               图片的高
'''   

df = pd.read_csv('GDP数据.csv')
# 删除空值
df.dropna(inplace=True)
# 清理重复值
df.duplicated()
df.describe()

city_name = ''
# 国家的名称
city_lst = list(df['国家'])
# 国家的集合
for i in range(len(df)):
    city_name += city_lst[i]
ls = jieba.lcut(city_name)
txt = " ".join(ls)
w = wordcloud.WordCloud(
    font_path=r'C:\Windows\Fonts\STXINWEI.TTF',
    width = 1000,height = 700,background_color = "white",
    )

w.generate(txt)
w.to_file("国家的词云图.png")
plt.imshow(w)


color_mask = np.array(Image.open("beijing.png"))
f = open('bookComments.txt','r',encoding ='gbk')
txt = f.read()
w =  wordcloud.WordCloud(
    font_path=" C:\\Windows\\Fonts\\STXINGKA.TTF",
                       background_color="white",
                       width=800,
                       height=600,
                       max_words=200,
                       max_font_size=80,
                       mask=color_mask,
                       ).generate(txt)
w.to_file('京东词云.png')
plt.imshow(w)

 

 

 

posted @ 2021-01-05 13:41  CodeYaSuo  阅读(94)  评论(0编辑  收藏  举报