1 # coding=utf-8 2 3 # np.loadtxt(fname,dtype=np.float,delimiter=None,skiprows=0,usecols=None,unpack=False) 4 # frame 文件/字符串或产生器,可以是.gz或者bz2压缩文件 5 # dtype 数据类型,可选,CSV的字符串以什么数据类型读入数组中,默认np.float 6 # delimiter 分隔字符串,默认是任何空格,改为 逗号 7 # skiprows 跳过前x行, 一般跳过第一行表头 8 # usecols 读取指定的列,索引,元组类型 9 # unpack 如果True, 读入属性将分别写入不同数组变量,False 读入数据只写入一个数组变量,默认False 10 11 12 ''' 13 import numpy as np 14 from matplotlib import pyplot as plt 15 from matplotlib import font_manager 16 17 us_file_path = r"/Users/vito/PycharmProjects/study_121/venv//youtube_video_data/US_video_data_numbers.csv" 18 uk_file_path = r"/Users/vito/PycharmProjects/study_121/venv/youtube_video_data/GB_video_data_numbers.csv" 19 20 t_us = np.loadtxt(us_file_path,delimiter=",",dtype="int") 21 22 # 读取数据 23 t_us_comments = t_us[:,-1] 24 print(t_us_comments.max(),t_us_comments.min()) 25 26 # 选出比5000小的数据 27 t_us_comments_n = t_us_comments[t_us_comments<=5000] 28 print(t_us_comments_n.max(),t_us_comments_n.min()) 29 30 31 d = 250 32 bin_nums = (t_us_comments_n.max() - t_us_comments_n.min())//d 33 34 # 绘图 35 plt.figure(figsize=(20,8),dpi=80) 36 plt.hist(t_us_comments_n,bin_nums) 37 plt.show() 38 ''' 39 40 import numpy as np 41 from matplotlib import pyplot as plt,font_manager 42 # from matplotlib import font_manager 43 us_file_path = r"/Users/vito/PycharmProjects/study_121/venv//youtube_video_data/US_video_data_numbers.csv" 44 uk_file_path = r"/Users/vito/PycharmProjects/study_121/venv/youtube_video_data/GB_video_data_numbers.csv" 45 46 # 读取数据 筛选数据 47 t_uk = np.loadtxt(uk_file_path,delimiter=",",dtype="int") 48 t_uk = t_uk[t_uk[:,1]<=500000] 49 50 t_uk_comment = t_uk[:,-1] 51 t_uk_like = t_uk[:,1] 52 53 plt.figure(figsize=(20,8),dpi=80) 54 plt.scatter(t_uk_like,t_uk_comment) 55 56 plt.show()