In the QGIS User interface, it is possible to view the Attribute Table for all the features of a Vector Layer.
Is there a way to directly read and write the Attribute Table in the Python API?
I searched for a long time and could not find it. I can create a table (pandas df) through iteration, but do not know if that is a good practice.
import pandas as pd attribute_table = list() for z in zip_code_layer.getFeatures(): attrib = z.attributes() attribute_table.append(attrib) headers = zip_code_layer.fields().names() attribute_df = pd.DataFrame(attribute_table, columns = headers) attribute_df.Zip_Code = attribute_df.Zip_Code.astype('int64')
My aim is to create additional columns to, or edit existing values in the pandas dataframe, attribute_df, and then write it back to the vector layer.
I know I can awkwardly extend the number of attributes, and update features one at a time, but I can't help thinking there has to be a better way.