There is a NDVI raster file of a corn field. My main goal is to find the 5 percentile of the field's NDVI and create a histogram of the NDVI values. The percentile data can be extracted directly with a python code. Things get trickier when I need to generate a histogram.

Currently, to create the histogram following things are being done in ArcPy -

  1. The NDVI image was converted to a point shapefile

  2. The attribute table is exported in .dbf formate. The dbf file is pretty large as it contains around half million pixel values. The .dbf file structure is as follows -

    enter image description here

The grid_code column is the NDVI pixel value.

  1. The dbf python library is being used to read the table. Then, all values are appended in an empty list and histogram is generated from the list using matplotlibs library.

It takes almost 1-2 mins to append the values into the list. Is there any other way to just access the specific column and make a histogram out of the .dbf file. I have tried filename[2] and it is providing all values including the first cell "grid_code".

A part of the whole code is provided below -

Temp_List = []

#importing the dbf file and appending each NDVI values the temp list
Table = DBF.Table(Data_Table)
for record in Table:

#percentile calculation for further use in yield map
percentile5 = np.percentile(Temp_List, 5) 

#properties of the histogram
bins = 100
n, bins, patches = plt.hist(Temp_List, bins, normed=1, facecolor='green', alpha=0.5)
plt.show(block = False)
  • 1
    Please take the Tour to better understand our "Focused question / Best answer" model. Your question is missing many significant details, including whether the .dbf is part of a shapefile or standalone, how arcpy is involved, and the code you have written to attempt the goal.
    – Vince
    Jun 13, 2018 at 17:34

1 Answer 1


Try converting NDVI to a point feature class in a file geodatabase instead of shapefile then use the da.SearchCursor to list all values:

SearchCursor establishes read-only access to the records returned from a feature class or table.

The listing should take maybe 10 s:

import arcpy

feature_class = r'C:\filegeodatabase.gdb\points' #Can also be a shapefile
fieldname = 'grid_code'

temp_list = [i[0] for i in arcpy.da.SearchCursor(feature_class, fieldname)]

#numpy code..

Or use RasterToNumPyArray:

Converts a raster to a NumPy array.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.