temp_list = df["Genre"].str.split(",").tolist()#[[],[],[]]
genre_list =list(set([i for j in temp_list for i in j]))#统计各分类做为列import numpy as np
zeros_df=pd.DataFrame(np.zeros((df.shape[0],len(genre_list))),columns=genre_list)#构造全0的数组#给每个电影出现的分类的位置赋值1for i inrange(df.shape[0]):
zeros_df.loc[i,temp_list[i]]=1# print(temp_list[i])#['Action', 'Adventure', 'Sci-Fi']# breakprint(zeros_df.head(3))#统计每个分类的电影的数量和
genre_count=zeros_df.sum(axis=0)#排序
genre_count=genre_count.sort_values()#画图
_x=genre_count.index
_y=genre_count.values
plt.figure(figsize=(20,8),dpi=80)
plt.bar(range(len(_x)),_y,width=0.3,color="orange")
plt.xticks(range(len(_x)),_x)
plt.show()