Looking a generic Python script to add a field and populate the field with conditions
I am looking for a script to allow users to add a text field to a .dbf table(e.g. landuse categories) and allow them to input/update the rows basing on what values in the GRIDCODE (numeric categories) field they think should be assigned into text categories.i.e. if GRIDCODE value is 4, the corresponding field value of landuse/landclass is “forest” etc.
Is there such a script in existence?
Or, do you have something similar that I can customise to create a new script?
The script will accept users' interactive input as parameters passed into the script.
Sincerely, David
Asked by: Marcus159 | Posted: 28-01-2022
Answer 1
When you say dbf table, are you referring to ESRI shape file dbf files, which are in fact dbase files? If so you could implement such a thing pretty easily with the python wrapper for shapelib, which also supports dbf files.
Answered by: Lydia271 | Posted: 01-03-2022Similar questions
python - Populate new column based on conditions in another column
I'm playing about with Python and pandas.
I have created a dataframe, I have a column (axis 1) called 'County' but I need to create a column called 'Region' and populate it like this (atleast I think):
If County column == 'Suffolk' or 'Norfolk' or 'Essex' then in Region column insert 'East Anglia'
If County column == 'Kent' or 'East Sussex' or 'West Sussex' then in Region Column insert 'South East'...
Populate values in an array if conditions are true in another array in Python
I have created an array d:
d = [[[1.60269836 1.97347391 1.76414466 1.53102548 1.35352821]
[1.0153325 1.53331695 1.36105004 1.76111151 1.62595392]
[1.5156144 1.77076004 1.24249056 1.94406171 1.98917422]]
[[1.44790465 1.46990159 1.48156613 1.92963951 1.11459211]
[1.10674091 1.57711027 1.85275685 1.84640848 1.34216641]
[1.63670185 1.69894884 1.45114395 1.09750849 1.09564564]]]
Which...
django - Iterating through large lists with potential conditions in Python
I have large chunks of data, normally at around 2000+ entries, but in this report we have the ability to look as far as we want so it could be up to 10,000 records
The report is split up into: Two categories and then within each Category, we split by Currency so we have several sub categories within the list.
My issue comes in efficiently calculating the various subtotals. I am using Django and pass a templ...
python - Race conditions in django
Here is a simple example of a django view with a potential race condition:
# myapp/views.py
from django.contrib.auth.models import User
from my_libs import calculate_points
def add_points(request):
user = request.user
user.points += calculate_points(user)
user.save()
The race condition should be fairly obvious: A user can make this request twice, and the application could pote...
python - Dynamic Event Conditions
Consider that we've a class named Foo that fires "ready" event when it's ready.
from observer import SubjectSet
class Foo:
def __init__(self):
self.events = SubjectSet()
self.events.create('ready')
def do_sth(self):
self.events.fire('ready')
As you see, do_sth method makes ready instances of the Foo class. But subclasses will want to add new tasks/conditions that have to ...
python - How to order by aggregate with conditions on fields of a relation
My code:
class School(models.Model): pass
class Student(models.Model):
school = models.ForeignKey(School)
TYPE_CHOICES = (
('ug', 'Undergraduate'),
('gr', 'Graduate'),
('al', 'Alumnus'),
)
type = models.CharField(max_length=2)
How do I obtain a QuerySet of Schools ordered by the number of Undergraduate Students?
Python: Looping over One Dictionary and Creating Key/Value Pairs in a New Dictionary if Conditions Are Met
I want to compare the values of one dictionary to the values of a second dictionary. If the values meet certain criteria, I want to create a third dictionary with keys and value pairs that will vary depending on the matches.
Here is a contrived example that shows my problem.
edit: sorry about all the returns, but stack overflow is not recognizing single returns and is running 3-4 lines onto one line, m...
How find values in an array that meet two conditions using Python
I have an array
a=[1,2,3,4,5,6,7,8,9]
and I want to find the indices of the element s that meet two conditions i.e.
a>3 and a<8
ans=[3,4,5,6]
a[ans]=[4,5,6,7]
I can use numpy.nonzero(a>3) or numpy.nonzero(a<8)
but not
numpy.nonzero(a>3 and a<8) which gives the error:
ValueError: The t...
python - Efficient way of phrasing multiple tuple pair WHERE conditions in SQL statement
I want to perform an SQL query that is logically equivalent to the following:
DELETE FROM pond_pairs
WHERE
((pond1 = 12) AND (pond2 = 233)) OR
((pond1 = 12) AND (pond2 = 234)) OR
((pond1 = 12) AND (pond2 = 8)) OR
((pond1 = 13) AND (pond2 = 6547)) OR
((pond1 = 13879) AND (pond2 = 6))
I will have hundreds of thousands pond1-pond2 pairs. I have an index on...
python - Create a new array from numpy array based on the conditions from a list
Suppose that I have an array defined by:
data = np.array([('a1v1', 'a2v1', 'a3v1', 'a4v1', 'a5v1'),
('a1v1', 'a2v1', 'a3v1', 'a4v2', 'a5v1'),
('a1v3', 'a2v1', 'a3v1', 'a4v1', 'a5v2'),
('a1v2', 'a2v2', 'a3v1', 'a4v1', 'a5v2'),
('a1v2', 'a2v3', 'a3v2', 'a4v1', 'a5v2'),
('a1v2', 'a2v3', 'a3v2', 'a4v2', 'a5v1'),
('a1v3', 'a2v3', 'a3v2', 'a4v2', 'a5v2'),
('a1v1', ...
python - Write conditions based on a list
I'm writing an if statement in Python with a lot of OR conditions. Is there an elegant way to do this with a list, within in the condition rather than looping through the list?
In other words, what would be prettier than the following:
if foo == 'a' or foo == 'b' or foo == 'c' or foo == 'd':
I've just taken up Python, and the language has me wanting to write better.
python - Applying conditions to dictionary key values while traversing through them
The Dictionary is as given below:
goodDay= {'Class':[1,1,0,0,0,1,0,1,0,1], 'Grade':[1,0,0,1,0,1,0,1,0,1]}
I want to code this way that i should get the count of "1" and also "0" in Class when my grade has value "1" and also vice versa i.e. when my grade has value "0".
So i will have to traverse through the list values for both and Class and Grade and then may be put this condition while...
Still can't find your answer? Check out these communities...
PySlackers | Full Stack Python | NHS Python | Pythonist Cafe | Hacker Earth | Discord Python