Hi guys, I am working on a python script and trying to filter fields having date before 1950 and putting in the count in a column as I did the number of zeroes, nulls and unknowns that is working perfectly except the date column one. can you please help me where I am not paying attention to make code working.
my code is as below
import arcpy
import pandas as pd
from arcgis.features import GeoAccessor
from sys import argv
from datetime import date
# Set the workspace to your geodatabase
geodatabase = r"Z:\path"
arcpy.env.workspace = geodatabase
# Specify the feature class to analyze
feature_class = "Shape_file"
# Get a list of all fields in the feature class
fields = arcpy.ListFields(feature_class)
# Create an empty list to store the results
results = []
# Iterate through each field
for field in fields:
field_name = field.name
field_type = field.type
# Count null and zero values using SearchCursor
null_count = 0
zero_count = 0
unknowns = 0
Default_Date = 0
with arcpy.da.SearchCursor(feature_class, [field_name]) as cursor:
for row in cursor:
if row[0] is None:
null_count += 1
elif field.type in ["Double", "Float", "Integer", "SmallInteger"] and row[0] == 0:
zero_count += 1
elif row[0] == 'unknown':
unknowns += 1
elif field.type in ["Date"] and row[0] <="1950-12-29":
Default_Date += 1
# Append the results to the list
results.append({
"Field": field_name,
"Type": field_type,
"Nulls": null_count,
"Zeroes": zero_count,
"Unknowns": unknowns,
"Default Date": Default_Date})
# Create a pandas DataFrame from the results
df = pd.DataFrame(results)
# Display the DataFrame as a table in the notebook
display(df)