I need to count the span of days an individual has been observed, from the first til the last observation day. There can be many observations per ID per day and not everyday has observations, hence the first and last dates are important.
The feature class contains many individuals, one row per observation per ID, so I need to group by ID. ID is a Text field, days are Date (also shows the time). I want to add the count of days to a new field (numeric) in the original datatable called NrDays. If need be I can create a new table and join on ID of course.
It seems simple but I cannot figure out how to do this in ArcGIS Pro. I need to be able to incorporate it into Model Builder, either by Python script or in a tool such as Calculate Field. In a script tool it seems hard to import Pandas for groupby function (the toolbox needs to be used by many different users), and in Calculate Field I don't know how to group by ID, and count the span of days in Arcade doesnt work: "DateDiff("d", Min($feature.Datum), Max($feature.Datum))"
Python script throws the error that ID is a Text field:
import arcpy
from arcpy import env
env.workspace = 'the database'
butterfly = r'butterfly_2019' # the feature class
for i in butterfly['ID']:
d1 = datetime.date.max('Datum')
d2 = datetime.date.min('Datum')
countdays = d2-d1
butterfly['NrDays'] = antal
out_location = 'the database'
arcpy.FeatureClassToGeodatabase_conversion(butterfly , out_location)
I know one major issue is with referencing the row ("i") which should be a group instead.