练习:英国和美国各自youtube1000的数据结合之前的matplotlib绘制出各自的评论数量的直方图
US_video_data_numbers.cs 数据分别是 点击 喜欢 不喜欢 评论
us_path = "D:/test/youtube_video_data/US_video_data_numbers.csv"
uk_path = "D:/test/youtube_video_data/GB_video_data_numbers.csv"
t1 = np.loadtxt(us_path,delimiter=",",dtype="int")
print(t1)
print("*"*50)
t2 = np.loadtxt(uk_path,delimiter=",",dtype="int")
print(t2)
[[4394029 320053 5931 46245]
[7860119 185853 26679 0]
[5845909 576597 39774 170708]
...
[ 142463 4231 148 279]
[2162240 41032 1384 4737]
[ 515000 34727 195 4722]]
**************************************************
[[7426393 78240 13548 705]
[ 494203 2651 1309 0]
[ 142819 13119 151 1141]
...
[ 109222 4840 35 212]
[ 626223 22962 532 1559]
[ 99228 1699 23 135]]
#获取us评论数据
us_comments = t1[:,-1]
#过滤选择比5000小的数据
us_comments = us_comments[us_comments<=5000]
print(us_comments)
#获取最大值和最小值,算差距,设置组距,算分成多少组
us_comment_max = us_comments.max()
us_comment_min = us_comments.min()
print(us_comment_max,us_comment_min)
d = 500
bin_num = (us_comment_max - us_comment_min)
print(bin_num)
#设置图像大小
plt.figure(figsize=(20,8),dpi=80)
plt.hist(us_comments,bin_num) #不加normed=True 表示直方频数图
plt.grid()
plt.show()
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/54e527effa68df0e82f28427c3415bfa.png)