I do the assignment using Pandas and use np.where () to create a column in the Pandas DataFrame with three possible values:
fips_df['geog_type'] = np.where(fips_df.fips.str[-3:] != '000', 'county', np.where(fips_df.fips.str[:] == '00000', 'country', 'state'))
The state of a DataFrame after adding a column is as follows:
print fips_df[:5] fips geog_entity fips_prefix geog_type 0 00000 UNITED STATES 00 country 1 01000 ALABAMA 01 state 2 01001 Autauga County, AL 01 county 3 01003 Baldwin County, AL 01 county 4 01005 Barbour County, AL 01 county
This column construction is verified by two statements. The first passes, and the second fails.
#
What is the difference between calling columns like fips_df.geog_type and fips_df ['geog_type'] that make my second statement fail?
ajrenold
source share