Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #107951

How to fill in abbreviation in one column based on state name in another column?

From David Shi <davidgshi@yahoo.co.uk>
Newsgroups comp.lang.python
Subject How to fill in abbreviation in one column based on state name in another column?
Date 2016-05-01 18:27 +0000
Message-ID <mailman.290.1462127444.32212.python-list@python.org> (permalink)
References <919174787.8635501.1462127259949.JavaMail.yahoo.ref@mail.yahoo.com> <919174787.8635501.1462127259949.JavaMail.yahoo@mail.yahoo.com>

Show all headers | View raw


Hello, I am back.  Thank you very much for your positive response.
I am trying to use Pandas apply to execute a lookup function, so that we can put abbreviation in a new column, in accordance to a state name in another column.
Does anyone knows how to make this to work?
Regards.DavidLook up functionstate_to_code = {"VERMONT": "VT", "GEORGIA": "GA", "IOWA": "IA"}#table['moa_state_name'] = map(lambda x: x.upper(), table['moa_state_name'])def convert_state(row):    abbrev1 =  state_to_code(table['moa_state_name']) #'aatest'    if abbrev1:         return abbrev1 ##state_to_code[abbrev[0]]    return np.nan#print convert_state(table['moa_state_name'])
table.insert(0, "abbrev", np.nan)
table['abbrev'] = table.apply(convert_state, axis=1)print state_to_code['ARKANSAS']

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

How to fill in abbreviation in one column based on state name in another column? David Shi <davidgshi@yahoo.co.uk> - 2016-05-01 18:27 +0000
  Re: How to fill in abbreviation in one column based on state name in another column? Rustom Mody <rustompmody@gmail.com> - 2016-05-01 20:31 -0700

csiph-web