This is a continuation of my previous question in an effort to build upon it.
Given the examples of my data below, I would like to be able to SUM a column (QUANTITY_SOLID) based upon a field, such as 'SEGMENT_LENGTH', and have the cursor write the SUM into a new field pertaining only to that field that it belongs to. So, in my example, this would be useful because the amount of 'QUANTITY_SOLID' material being disseminated onto a road is broken up into 'SEGMENT_LENGTH' which is a road segment. My previous question allowed for me to calculate the total of 'QUANTITY_SOLID' but it was for all roads (or all roads that were in my specific query). In order to do some GIS analysis and show which roads received heavier application and overall larger quantity total, I want there to be a separate SUM for each 'SEGMENT_LENGTH'.
In general, I am not looking for someone to write the code for me or to necessarily solve this specific issue. My larger question, so I can learn for future coding, is how do I go about coding some sort of 'WHERE' clause in Python where I could be more flexible with my current script?
Thanks in advance for any help!
This is my previous code (Thanks to Aaron):
import arcpy
# Define the feature class
fc = r'C:\path\to\your\fc'
# Use a generator expression to populate a list from the 'QUANTITY_SOLID' field
b = sum(row[0] for row in arcpy.da.SearchCursor(fc, 'QUANTITY_SOLID'))
with arcpy.da.UpdateCursor(fc, ['QUANTITY_SOLID_SUM']) as cursor:
for row in cursor:
row[0] = b
cursor.updateRow(row)