I am working on a dataframe in julia and one column has zipcodes. In certain instances, a State code is appended in front of zip code.
For example: if zipcode is 123456, and state is ab, it looks like ab 123456.
There are multiple values like that in the column. How can I replace all "ab " with "" in that column.
You can use replace function with a regexp matching your pattern and broadcast it over all entries of the column like this:
julia> using DataFrames
julia> df = DataFrame(x = ["ab x", "y", "ab z"])
3×1 DataFrame
Row │ x
│ String
─────┼────────
1 │ ab x
2 │ y
3 │ ab z
julia> df.x .= replace.(df.x, r"^ab " => "")
3-element Vector{String}:
"x"
"y"
"z"
julia> df
3×1 DataFrame
Row │ x
│ String
─────┼────────
1 │ x
2 │ y
3 │ z
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With