一列的熊猫数据框填充数组值与另一列的值

时间:2019-12-06 08:05:12

标签: python pandas dataframe data-science padding

我有一个像这样的数据框:

enter image description here

我正在尝试按照严重性值以相同的顺序,用严重性值用零填充事件行数组:

**Unique severity values order**: ['INFO' 'CRITICAL' 'MAJOR' 'MINOR' 'OK' 'UNKNOWN' 'WARNING'
 'itsm_incident_status=' 'itsm_incident_status=Assigned'
 'itsm_incident_status=In Progress' 'itsm_incident_status=Pending'
 'itsm_incident_status=Resolved']

Expected outcome of Events array for labels :

attribut : [INFO]    [1813,0,0,0,0,0,0,0,0,0,0,0]

baseline : [3513,10,62,317,126,42,20,6,1,3,2,14]

cmdb : [OK]   [0,0,0,0,1804,0,0,0,0,0,0,0]

and so on, so that it can accurately map with Severity values per label in the charts :

I tried below code but it's not working accurately : 

def pad_event_count(count):
        print('count ',count)
        for index,s in enumerate(y):
            print('current s ',s)
            row_str = "".join(parsed.Severity[index])
            print('Severity ',row_str)
            if row_str != s:
                print('not equal')
                count.append(0)
            else:
                print('equal appending count')
                #count.append(count)

parsed.events.apply(lambda x : pad_event_count(x))

0 个答案:

没有答案