I have a field that has multiple names for the same company, for several companies. I would like to build a script to replace the name for each company...
example: replace( [OPERATOR],"ANADARKO E & P ONSHORE LLC","ANADARKO")
Find | Replace |
ANADARKO E & P ONSHORE LLC | ANADARKO |
ANADARKO E&P ONSHORE | ANADARKO |
ANADARKO PET | ANADARKO |
ANADARKO PET CORP | ANADARKO |
ANADARKO PETROLEUM CORPORATION | ANADARKO |
CHESAPEAKE LIMITED PARTNERSHIP | CHESAPEAKE |
CHESAPEAKE OPERATING INC. | CHESAPEAKE |
CHESAPEAKE OPERATING INCORPORATED | CHESAPEAKE |
CHESAPEAKE OPERATING, INC. | CHESAPEAKE |
CHESAPEAKE OPERG INC | CHESAPEAKE |
How can I build a single script for all replacements?
Thanks!
def calc(field):
if 'ANADARKO' in field:
return 'ANADARKO'
elif 'CHESAPEAKE' in field:
return 'CHESAPEAKE'
OPERATOR=
calc( !OPERATOR!)
Still failed. I am having no luck.
it appears you are trying to calculate values for an 'OPERATOR' field... if so, you can't use values that are already in that field. You need to make a new field of the same data type... say ... 'NEW_OP'... then you make that field active and use the calculator expression
cal(!NEW_OP!)
of course this assumes that your indentation is totally correct etc etc
Melissa,
Can you upload a zipped sample of your data?
I'm sorry, I'm new here - where do I go to upload data?
When replying click on Use Advanced Editor at the top right:
Then you will see the Attach option in the lower left hand corner:
Thanks, I had to reply to original message to see the advanced option.
Did you try the suggestion https://community.esri.com/thread/206396-help-with-building-script-for-multiple-replacements-in-fiel... because your haven't clarified the name of the field you have the data in and whether or not you are trying to add this to a field of the correct type. You calculator expression was incorrect as it was posted.
BTW, it appears to have been answered... so what was the solution?
I did try it. I added a text field named it NewOp, selected it, then ran field calc. It didn't work. Its time I took a scripting class... the basics are not working in my new job.
I didn't report that this was answered... unless it was by accident when trying to find the advanced editor. Ugh.