У меня есть файл csv:
Notation Level Mode Label
AAA 1 Mode1 AG, GH
BBB 2 Mode2 AG, LL
CCC 3 Mode3 GH, LL
DDD 1 Mode4 AG, EE
AAA 2 Mode5 GH, LL
Я считаю общее количество AG по метке col:
Вот код:
data = df[df['Label'].str.contains('AG')].groupby([df['Notation'], df['Level'], df['Mode']]).size().reset_index(name= Percentage)
data['Percentage'] = (data['Percentage']/10)*100
data['Percentage'] = data['Percentage'].astype(str) + '%'
у меня есть:
Notation Level Mode Percentage
AAA 1 Mode1 100%
BBB 2 Mode2 100%
DDD 1 Mode4 100%
Как мне получить процент, даже если он не содержит 'AG' в этом поле: Что-то вроде этого:
Notation Level Mode Percentage
AAA 1 Mode1 100%
BBB 2 Mode2 100%
CCC 3 Mode3 0%
DDD 1 Mode4 100%
AAA 2 Mode5 0%