in datatables library i want to iterate through rows using this expectedfields =…
- User
in datatables library i want to iterate through rows using this expected_fields = [row['FIELD'] for row in self.data_controller_table if row['TABLE'] == table_name] but row value is returned as a column and not a row raising the error column TABLE is not in frmae
- Assistant
It seems like you are trying to work with a pandas DataFrame (or a similar structure) and expecting each
rowin your iteration to be a dictionary where you can access values by keys (columns). The error you are encountering hints that the way you are iterating over the DataFrame is not returning the rows as dictionaries but rather treatingrowas a column name.To properly iterate over rows in a pandas DataFrame and access each row as a dictionary, you should use the
.iterrows()method. This method iterates through the DataFrame rows, returning each row as a tuple containing the row index and the row data as a pandas Series, which can be converted to a dictionary. Here's how you can achieve what you are trying to do: