или решение на месте - все включает цикл уровня Python.

дал фрейм данных:

[in] testing_df =pd.DataFrame(test_array,columns=['transaction_id','product_id'])

# Split the product_id's for the testing data
testing_df.set_index(['transaction_id'],inplace=True)
testing_df['product_id'] = testing_df['product_id'].apply(lambda row: row.split(','))

[out]                 product_id
transaction_id                 
001                       [P01]
002                  [P01, P02]
003             [P01, P02, P09]
004                  [P01, P03]
005             [P01, P03, P05]
006             [P01, P03, P07]
007             [P01, P03, P08]
008                  [P01, P04]
009             [P01, P04, P05]
010             [P01, P04, P08]

Как теперь я могу удалить «P04» и «P08» из результатов?

Я пытался:

# Remove P04 and P08 from consideration
testing_df['product_id'] = testing_df['product_id'].map(lambda x: x.strip('P04'))

testing_df['product_id'].replace(regex=True,inplace=True,to_replace=r'P04,',value=r'')

Однако ни один из вариантов не работает.

Типы данных:

[in] print(testing_df.dtypes)
[out] product_id    object
dtype: object

[in] print(testing_df['product_id'].dtypes)
[out] object

Ответы на вопрос(0)

Ваш ответ на вопрос