【发布时间】:2023-01-25 17:04:56
【问题描述】:
我有一个像下面这样的数据框
|Animals | Type | Year |
|Penguin AVES | Omnivore | 2015 |
|Caiman REP | Carnivore | 2018 |
|Komodo.Rep | Carnivore | 2019 |
|Blue Jay.aves | Omnivore | 2015 |
|Iguana+rep | Carnivore | 2020 |
我想从“动物”列的值中提取最后的特定单词(例如 AVES 和 REP),并将其移动到下一行,同时保留整行的值。除了 AVES 和 REP 之外,还有几个特定的词。它不是很干净(如特定单词前的空格、点和“+”运算符所示)。预期的新 DataFrame 如下所示
| Animals | Type | Year |
| Penguin AVES | Omnivore | 2015 |
| AVES | Omnivore | 2015 |
| Caiman REP | Carnivore | 2018 |
| REP | Carnivore | 2018 |
| Komodo.Rep | Carnivore | 2019 |
| Rep | Carnivore | 2019 |
| Blue Jay.aves | Omnivore | 2015 |
| aves | Omnivore | 2015 |
| Iguana+rep | Carnivore | 2020 |
| rep | Carnivore | 2020 |
我正在考虑使用负索引来拆分字符串,但我对这个特定问题的 lambda 函数感到困惑。知道我应该如何解决这个问题吗?提前致谢。
【问题讨论】: