'Remove a particular character ("-") and characters after it in a column of dataframe
From my dataframe column, I want to remove the "-" character and the letters following it.
For eg.
Input dataframe
Name Subset
Apple AP-, GP-
Bat BT-01A, KL
Cat CT-L, OK-01
Output desired
Name Subset
Apple AP,GP
Bat BT,KL
Cat CT,OK
Solution 1:[1]
import pandas as pd
dataFrame = {
"Name": "Subset",
"Apple": "AP-", "GP-",
"Bat": "BT-01A", "KL"
"Cat": "CT-L", "OK-01"
}
pd.DataFrame(dataFrame).iloc[:, 1].str.split("-", expand=True)[0]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
