How to search out all Zip codes and replace with the first 2 digits, in a Pandas dataframe, with the use of regex?

Irving Duran irving.duran at gmail.com
Wed Mar 22 14:37:55 EDT 2017


You can do the following

df['field'] = df.replace(r'(?<![\d])(\d{2})', '', regex=True)




Thank You,

Irving Duran

On Mon, Mar 20, 2017 at 9:53 AM, David Shi via Python-list <
python-list at python.org> wrote:

> Hi, there,
> Can anyone help?
> How to search out all Zip codes and replace with the first 2 digits, in a
> Pandas dataframe, with the use of regex?
>
> For instance, a ZIP code 33132 was found and replaced with 33.
> Looking forward to hearing from you.
> Regards.
> David
> --
> https://mail.python.org/mailman/listinfo/python-list
>


More information about the Python-list mailing list