小编Con*_*nor的帖子

删除熊猫数据框列中的多个子字符串

我在熊猫数据框中有一列成分。我需要删除除成分名称之外的所有内容(例如:1/3 杯腰果 > 腰果)。

输入

    recipe_name                                ingredient
0   Truvani Chocolate Turmeric Caramel Cups    ? cup cashews
1   Truvani Chocolate Turmeric Caramel Cups    4 dates
2   Truvani Chocolate Turmeric Caramel Cups    1 tablespoon almond butter
3   Truvani Chocolate Turmeric Caramel Cups    3 tablespoons coconut milk
4   Truvani Chocolate Turmeric Caramel Cups    ½ teaspoon vanilla extract
Run Code Online (Sandbox Code Playgroud)

预期产出

    recipe_name                                ingredient
0   Truvani Chocolate Turmeric Caramel Cups    cashews
1   Truvani Chocolate Turmeric Caramel Cups    dates
2   Truvani Chocolate Turmeric Caramel Cups    almond butter
3 …
Run Code Online (Sandbox Code Playgroud)

python regex pandas

5
推荐指数
1
解决办法
2607
查看次数

标签 统计

pandas ×1

python ×1

regex ×1