'Using replace in pandas
I'm having trouble replacing values in a column. I have data coming into the column as a letter attached to a number.
output
J/2022
F/2022
I would like my output to be just the letters(Like J instead of J/2022)
My current code
df['Month'].replace(to_replace='J/2022', value='J')
But when I do this the output still comes out as J/2022. How to I replace J/2022 with J?
Solution 1:[1]
If your just trying to get the first letter of the string that is "J/2022" and there is always one letter simply do df["month'].map(lambda x: x[0]) this would produce a series of all of the letters.
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 | jonlev03 |
