You will need a module called dbf
, accessible via pypi ( pip install dbf
). Here is a snippet of how you can add and remove fields from a table:
import dbf table = dbf.Table('t1', 'field1 N(12, 0)') for record in ((11110481123,), (12150480021,)): table.append(record) table.close() # extend the existing table dbf.add_fields('t1', 'field2 N(4, 0)') table = dbf.Table('t1') records = table.sql('select *') for record in records: record.field2 = int(str(record.field1)[-4:]) table.close() dbf.delete_fields('t1', 'field1')
Although it would be much less to calculate the intensity, just go to the first field and change it to save the last 4 digits of its value.
source share