TransWikia.com

Choosing first letters of words in attribute table using Python Parser of ArcMap Field Calculator

Geographic Information Systems Asked on May 30, 2021

I want to write a Python script in Field Calculator which can pick up or choose the fist letters of words and put them in a new field.

For example:

Lepidium catapycnon..........> Lc
Gold blossom tree............> Gbt

3 Answers

Expanding on the answer from cag I just tested the code below which should do what you want. You just need to have your original and new field (called OrigField and NewField in my test) already in the attribute table.

Parser

Python

Pre-Logic Script Code

def Abbreviate(origFieldValue):
  newFieldValue = "".join(item[0] for item in origFieldValue.split())
  return newFieldValue

NewField =

Abbreviate(!OrigField!)

Correct answer by PolyGeo on May 30, 2021

If you can write in SQL it would be something like SELECT SUBSTR(Column, 1, 2) where Column would be the name of the corresponding attribute column.

Answered by FishHead on May 30, 2021

You can do it by splitting the words by groups of consecutive whitespaces and taking the first letter of each word.

There is a python example at Upper case first letter of each word in a phrase.

Answered by César Argul García on May 30, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP