![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/01e2f4cf0a5c89ce8dd61f9249f79cc7.png)
import numpy as np
score1 = np.loadtxt("scores.csv", delimiter=",", skiprows=1)
arr_midtermExam = score1[:, 0]
arr_finalExam = score1[:, 1]
arr1_midtermExam = arr_midtermExam[(arr_midtermExam > 60) & (arr_midtermExam < 80)].astype("uint8")
arr1_finalExam = arr_finalExam[(arr_finalExam > 60) & (arr_finalExam < 80)].astype("uint8")
arr2_midtermExam = arr_midtermExam[(arr_midtermExam > 80) & (arr_midtermExam < 90)].astype("uint8")
arr2_finalExam = arr_finalExam[(arr_finalExam > 80) & (arr_finalExam < 90)].astype("uint8")
arr3_midtermExam = arr_midtermExam[arr_midtermExam > 90].astype("uint8")
arr3_finalExam = arr_finalExam[arr_finalExam > 90].astype("uint8")
print("期中考试介乎60分到80分的分数: ", arr1_midtermExam)
print("期末考试介乎60分到80分的分数:", arr1_finalExam)
print("期中考试介乎80分到90分的分数:", arr2_midtermExam)
print("期末考试介乎80分到90分的分数:", arr2_finalExam)
print("期中考试超过90分的分数: ", arr3_midtermExam)
print("期末考试超过90分的分数: ", arr3_finalExam)
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/2bca92583310996ac748c3fa52453357.png)
import numpy as np
from matplotlib import pyplot as plt
from matplotlib.font_manager import FontProperties
font = FontProperties(fname=r"c:\windows\fonts\simsun.ttc", size=12)
UK_youtube_data = np.loadtxt("GB_video_data_numbers.csv", delimiter=",", skiprows=1, dtype="uint8")
USA_youtube_data = np.loadtxt("US_video_data_numbers.csv", delimiter=",", skiprows=1, dtype="uint8")
UK_click = UK_youtube_data[:, 0]
UK_like = UK_youtube_data[:, 1]
UK_dislike = UK_youtube_data[:, 2]
UK_comment = UK_youtube_data[:, 3]
USA_click = USA_youtube_data[:, 0]
USA_like = USA_youtube_data[:, 1]
USA_dislike = USA_youtube_data[:, 2]
USA_comment = USA_youtube_data[:, 3]
range_number = max(max(UK_comment), max(USA_comment)) - min(min(UK_comment), min(USA_comment))
b = 5
bins = int(round(range_number)/b)
plt.hist([UK_comment, USA_comment], bins, label=["UK", "USA"])
plt.xlabel("评论数", fontproperties=font)
plt.ylabel("频数", fontproperties=font)
plt.legend(loc="upper right", prop=font)
plt.title("YouTube的评论数直方分布图", fontproperties=font)
plt.show()
range_number = max(max(UK_comment), max(UK_like)) - min(min(UK_comment), min(USA_like))
b = 5
bins = int(round(range_number)/b)
plt.hist([UK_comment, UK_like], bins, label=["评论数", "喜欢数"])
plt.ylabel("频数", fontproperties=font)
plt.legend(loc="upper right", prop=font)
plt.title("英国YouTube上评论数和喜欢数的直方分布图", fontproperties=font)
plt.show()
print("拼接0之后,英国的数据:")
UK_zeros = np.zeros((len(UK_comment), 1), dtype="uint8")
arr_zero_UK = np.hstack((UK_youtube_data, UK_zeros))
print(arr_zero_UK)
print()
print("拼接1之后,美国的数据:")
USA_ones = np.ones((len(USA_comment), 1), dtype="uint8")
arr_one_USA = np.hstack((USA_youtube_data, USA_ones))
print(arr_one_USA)
print()
print("英国和美国垂直拼接后的数据: ")
arr_UK_USA = np.vstack((arr_zero_UK, arr_one_USA))
print(arr_UK_USA)