Python——DataFrame中,中文列的筛选

中文筛选的方法:

筛选出A列重庆的行:

data.A==‘重庆’ / data[‘A’]==‘重庆’

筛选出A列包含重庆的行业(答案中有:重庆/北京和重庆):
data.A.str
筛选出A列分别是重庆和成都的行业:
data.A.isin([‘重庆’,’成都’])
筛选出在dataframe2的A列中包含dataframe1的B列的所有选项:

data2.A.isin(data1.index.tolist())

例如:原数据(data_clean):(数据总共超过10w条)
Python——DataFrame中,中文列的筛选_第1张图片
整理出以好评率排序的表格:

data_director = data_clean.groupby(‘导演’).sum()[[‘好评数’,‘评分人数’]]
data_director[‘好评率’]=data_director[‘好评数’]/data_director[‘评分人数’]
data_director_new = data_director.sort_values(by=‘好评率’,ascending=False)

结合data_clean,查看包含导演王静的作品有哪些?

data_director_wangjing = data_clean[data_clean.导演.str.contains(‘王静’)]
data_director_wangjing = data_clean[data_clean.导演.str.contains(‘王静’)].drop_duplicates([‘整理后剧名’])

结合data_clean,查看只有王静作为导演的作品有哪些?

data_director_onlywangjing = data_clean[data_clean.导演==‘王静’]
data_director_onlywangjing = data_clean[data_clean.导演==‘王静’].drop_duplicates([‘整理后剧名’])

结合data_clean,查看好评率前20的导演的作品有哪些?

data_directorTOP20 = data_clean[data_clean.导演.isin(data_director_new[:20].index.tolist())]
data_directorTOP20 = data_clean[data_clean.导演.isin(data_director_new[:20].index.tolist())].drop_duplicates([‘整理后剧名’])


原文:https://blog.csdn.net/weixin_43291997/article/details/83098660
感谢原作者

你可能感兴趣的:(python,问题解决)