我有一个数据框,我使用了 .groupby() 和 .agg() 函数。
movieProperties = combined_df.groupby(['movieId', 'title', 'genres']).agg({'rating': ['count', 'mean']})
这是创建新数据框的代码。但是我似乎无法再以相同的方式访问列了。如果我尝试,movieProperties['genres']我总是会收到 KeyError。如何再次访问这个新数据框中的列?
我有两个列表my_genre和list_of_genres。我想要一个函数来检查是否my_list[index]在list_of_genres并转换list_of_genres[index2]成1if的情况。
list_of_genres = ['Adventure', 'Animation', 'Children', 'Comedy', 'Fantasy', 'Drama', 'Romance', 'Action', 'Thriller', 'Sci-Fi', 'Crime', 'Horror', 'Mystery', 'IMAX', 'Documentary', 'War', 'Musical', 'Western', 'Film-Noir']
my_genre = ['Action', 'Crime', 'Drama', 'Thriller']
Run Code Online (Sandbox Code Playgroud)
预期结果:
[0 0 0 0 0 1 0 1 1 0 1 0 0 0 0 0 0 0 0]
data type : np.array
Run Code Online (Sandbox Code Playgroud)
最终,我想将执行此操作的功能应用于包含流派的pandas列。