这个是前10多粉丝的排名情况,可以看出北上广依然是电影用户的主力。其中北京的人数居然是上海,广州之和还要多。
可以看出男女比例还是男的多一些,这也是可能男生喜欢的电影更广泛一些导致的。
接下来我又统计了一下前十名粉丝最多的用户,发现只有2个女生,所以看来时光网男生更愿意发言,更容易吸引用户的关注。
具体代码如下:
import pymysql import jieba import numpy as np from wordcloud import WordCloud, ImageColorGenerator import PIL.Image as Image import matplotlib.pyplot as plt plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签 plt.rcParams['axes.unicode_minus']=False #用来正常显示负号 # num_list = [1.5,0.6,7.8,6] # plt.bar(range(len(num_list)), num_list) # plt.show() X = np.arange(8)+1 print(X+0.35) # 打开数据库连接 db = pymysql.connect("xxx.xxx.xxx.xxx", "root", "root", "movie") # 使用 cursor() 方法创建一个游标对象 cursor cursor = db.cursor() # 使用 execute() 方法执行 SQL 查询 sql = "SELECT mtime_user.place,count(*) from mtime_user group by mtime_user.place order by count(mtime_user.place) desc limit 10" cursor.execute(sql) num_list = [] bar_list = [] data = cursor.fetchall() for item in data: num_list.append(item[1]) bar_list.append(item[0]) print(num_list) print(bar_list) plt.bar(bar_list,num_list,0.8) plt.show() labels = ['男','女'] man = 0 woman = 0 sql = "select sex,count(*) from mtime_user group by sex" cursor.execute(sql) data = cursor.fetchall() for item in data: if item[0]==1: man = item[1] else: woman = item[1] sizes = [man/(man+woman),woman/(man+woman)] print(sizes) explode = [0,0] plt.pie(sizes,explode=explode,labels=labels,autopct='%1.1f%%',shadow=False,startangle=90) plt.show() sql = "select nickname,fensicount from mtime_user order by fensicount desc limit 10" cursor.execute(sql) data = cursor.fetchall() name_list = [] sex_list = [] explode = [0,0,0,0,0,0,0,0,0,0] for item in data: name_list.append(item[0]) sex_list.append(item[1]) plt.pie(sex_list,explode=explode,labels=name_list,autopct='%1.1f%%',shadow=False,startangle=90) plt.show() # 关闭数据库连接 db.close()
表结构:
CREATE TABLE `mtime_user` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `uid` CHAR(50) NOT NULL COMMENT '用户 id' COLLATE 'utf8_unicode_ci', `nickname` VARCHAR(20) NOT NULL COMMENT '用户昵称' COLLATE 'utf8_unicode_ci', `place` CHAR(10) NOT NULL COMMENT '地点' COLLATE 'utf8_unicode_ci', `sex` TINYINT(1) NOT NULL COMMENT '性别 男1 女2', `fensicount` SMALLINT(6) NOT NULL COMMENT '粉丝数', `noticecount` SMALLINT(6) NOT NULL COMMENT '关注数', PRIMARY KEY (`id`) ) COMMENT='时光影人表' COLLATE='utf8_unicode_ci' ENGINE=MyISAM AUTO_INCREMENT=193402;