我想核对一下数字旁边的单词。 例如,我的数据框中有以下列: 食谱
Halve the clementine and place into the cavity along with the bay leaves. Transfer the duck to a medium roasting tray and roast for around 1 hour 20 minutes.
Add the stock, then bring to the boil and reduce to a simmer for around 15 minutes.
2 heaped teaspoons Chinese five-spice
100 ml Marsala
1 litre organic chicken stock
我想得到一个新的专栏,在那里我提取它们:
New Column
[1 hour, 20 minutes]
15 minutes
2 heaped
100 ml
1 litre
因为我需要与一系列值进行比较:
to_compare= ["1 hour", "20 litres", "100 ml", "2", "15 minutes", "20 minutes"]
查看每行共有多少个元素。 谢谢你的帮助
我们将
Series.str.extractall
与模式numbers - space - letter
一起使用。然后我们检查to_compare
中有哪些匹配项,最后我们使用GroupBy.sum
来获得我们有多少个匹配项另外,
matches
返回:要在列表中获取这些信息,请使用:
您可以使用regex构建模式,该模式可以提取数字和以下单词,然后将此函数应用于数据帧的整个列
使用
to_compare
和列表提取公共值:相关问题 更多 >
编程相关推荐