У меня есть Dataframe с именем 'new_api_df'
со столбцом с именем new_api_df['Categories']
, который содержит список словарей:
[{'CallId': 22143866, 'BucketId': 1953, 'SectionId': 1256, 'BucketFullName': 'Categories.Filters.No Sale Made', 'Weight': 1.0}
, {'CallId': 22143866, 'BucketId': 2016, 'SectionId': 1255, 'BucketFullName': 'Categories.Imported.Objections', 'Weight': 3.0}
, {'CallId': 22143866, 'BucketId': 2017, 'SectionId': 1255, 'BucketFullName': 'Categories.Imported.Touting Benefits', 'Weight': 1.0}
]
Я хочу взять каждое 'BucketFullName' и поместить эти значения в список в отдельный столбец new_api_df['category_list']
как таковой:
['Categories.Filters.No Sale Made', 'Categories.Imported.Objections', Categories.Imported.Touting Benefits']
Я пытался использовать списочное понимание, например:
new_api_df['category_list'] =[item['BucketFullName'] for dictionary in new_api_df['Categories'] for item in dictionary]
но получите ошибку: ValueError: Length of values does not match length of index
Я также пытался применить и составить список: new_api_df['category_list'] = new_api_df['Categories'].apply([item['BucketFullName'] for dictionary in new_api_df['Categories'] for item in dictionary])
, но я получаю следующую ошибку: AttributeError: 'Categories.Filters.No Sale Made' is not a valid function for 'Series' object
I Также пробовал: new_api_df['category_list'] = df['Categories'].apply(lambda x: x['BucketFullName'])
, но получаю ошибку: TypeError: list indices must be integers or slices, not str
new_api_df кусочки:
new_api_df.loc [0]:
Contact {'Id': 22143866, 'Type': 'Call', 'WavPath': '\...
RecordInfo {'Id': 22143866, 'RowNumber': 1, 'TotalRowCoun...
Measures {'ID': 22143866, 'TotalHoldCount': 0, 'Agitati...
Others {'ConfidenceAverage': 69, 'SequenceID': None, ...
Sections [{'CallId': 22143866, 'SectionId': 1041, 'Sect...
Categories [{'CallId': 22143866, 'BucketId': 1953, 'Secti...
Scores [{'CallId': 22143866, 'ScoreId': 399, 'ScoreNa...
ScoreComponents [{'CallId': 22143866, 'ScoreComponentId': 4497...```