我正在嘗試將拼寫者的位置更改為簡單的格式。通過將 RW 更改為前鋒或將 CM 更改為中場。一個單元格中只有幾個值。如何合并或洗掉單元格中的其他值?
| 播放器 | player_positions |
|---|---|
| 梅西 | RW、ST、CF |
| 羅納爾多 | ST,LW |
我如何將 RW、ST、CF 簡單地更改為 Forward?我正在嘗試:
df.replace(to_replace=r'^RW', value='Forward', regex=True)
但后來我得到:
| 播放器 | player_positions |
|---|---|
| 梅西 | 前鋒,ST,CF |
| 羅納爾多 | ST,LW |
uj5u.com熱心網友回復:
您可以在替換陳述句中添加所有內容。
df = df.replace(to_replace=r'^RW, ST, CF', value='Forward', regex=True)
或者
df = df.replace(to_replace=r'^RW\D*', value='Forward', regex=True)
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/493415.html
標籤:Python 熊猫 数据框 jupyter-笔记本
