'Python Pandas: How to insert a new column from function of existing column
I have a Pandas dataset which contains a column containing postcode data.
For example "SW12 0ND" is a postcode from a row in the data.
I want to do several things
- Insert a new column, populated with values obtained from...
- ...a function applied to the existing column...
- ...where the function splits the postcode (string) by space characters and returns the first element
In other words, the new column takes the first part of the postcode: "SW12 0ND" -> "SW12"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
