我想找出列中具有特定值的行的百分比.并找到其他两列的每个组合的百分比.
以下是df示例:
data =[['North Shields','UK','Y'],['North Shields','Foreign','N']]
df = pd.DataFrame(data, columns = ['Port','Type','Shellfish Licence licence (Y/N)']
df
我try 了以下方法,但出现了一个关键错误,可能是因为我无法以这种方式对两列进行Groupby.
port_shel_df = landing_fish_merge['Shellfish Licence licence
(Y/N)'].eq('Y').groupby(port_merge_lic_df['Port','Type]).mean().reset_index(name='Shellfish
license
percentage')
port_shel_df = port_shel_df.set_index('Port')
port_shel_df[:1]