Check for the existence of a value in a field

514
1
02-27-2020 09:47 AM
EricAnderson_DHS
Occasional Contributor

Hey everyone,

ArcGIS API for Python 1.7.0

We currently have a script that writes to a feature layer in our Portal that records the username and last login of all users who logged in within the last 24 hours. Each night it wipes all records in the layer and writes new ones, again, for only the usernames who have logged in within the past 24 hours. 

Our goal now is to identify "power users", meaning those who logged in at least once in the last 24 hours. We're writing to a new layer in the feature service. The goal is to have some sort of counter which is updated every night, and each value in the 'username' field is their username, and a count field will be updated. The part I'm struggling with is determining if the username value already exists in the username field, and if so, just send an edit_features(updates=). Otherwise, if the username value does not exist, send an edit_features(adds=). 

Any general guidance on how this would be accomplished would be truly appreciated.

Thanks!

0 Kudos
1 Reply
J_R_Matchett
New Contributor III

You can get a list of the unique values in a column from a spatially-enabled data frame, for example:

power_users = power_users_layer.query(as_df=True)
existing_users = power_users.username.unique()
‍‍‍

Then use the in operator to check if a given user is in that list. If you post the code you have so far we could give some more specific guidance.

0 Kudos